@@ -265,39 +265,53 @@ private void CompileProject(CSharpCompilation compilation, CompilerData compiler
265265 continue ;
266266 }
267267
268+ string diagnosticMessage = diagnostic . GetMessage ( ) ;
269+
270+ _logger . LogDebug ( "[{0}] [{1}] Diagnostic - {2}" , diagnostic . Id , diagnostic . Severity , diagnosticMessage ) ;
271+
268272 if ( diagnostic . Location . SourceTree != null )
269273 {
270- SyntaxTree tree = diagnostic . Location . SourceTree ;
271- string fileName = Path . GetFileNameWithoutExtension ( tree . FilePath ) ?? "UnknownFile" ;
272- FileLinePositionSpan span = diagnostic . Location . GetLineSpan ( ) ;
273- int line = span . StartLinePosition . Line + 1 ;
274- int charPos = span . StartLinePosition . Character + 1 ;
274+ SyntaxTree syntaxTree = diagnostic . Location . SourceTree ;
275+ string fileName = Path . GetFileNameWithoutExtension ( syntaxTree . FilePath ) ?? "UnknownFile" ;
276+ FileLinePositionSpan lineSpan = diagnostic . Location . GetLineSpan ( ) ;
277+ int line = lineSpan . StartLinePosition . Line + 1 ;
278+ int position = lineSpan . StartLinePosition . Character + 1 ;
275279
276- if ( compilation . SyntaxTrees . Contains ( tree ) && diagnostic . Severity == DiagnosticSeverity . Error )
280+ switch ( diagnostic . Severity )
277281 {
278- compilation = compilation . RemoveSyntaxTrees ( tree ) ;
282+ case DiagnosticSeverity . Warning :
283+ {
279284
280- string diagnosticMessage = diagnostic . GetMessage ( ) ;
285+ break ;
286+ }
287+ case DiagnosticSeverity . Error :
288+ {
289+ compilerMessage . Errors ??= new List < CompilerError > ( ) ;
290+ compilerMessage . Errors . Add ( new CompilerError
291+ {
292+ Message = diagnosticMessage ,
293+ File = fileName ,
294+ Line = line ,
295+ Position = position
296+ } ) ;
281297
282- _logger . LogError ( "Failed to compile {0} - {1} (L: {2} | P: {3}) | Removing from project" ,
283- fileName , diagnosticMessage , line , charPos ) ;
298+ break ;
299+ }
300+ }
284301
285- compilerMessage . Errors ??= new List < CompilerError > ( ) ;
286- compilerMessage . Errors . Add ( new CompilerError
287- {
288- Message = diagnosticMessage ,
289- File = fileName ,
290- Line = line ,
291- Position = charPos
292- } ) ;
302+ if ( compilation . SyntaxTrees . Contains ( syntaxTree ) && diagnostic . Severity == DiagnosticSeverity . Error )
303+ {
304+ compilation = compilation . RemoveSyntaxTrees ( syntaxTree ) ;
305+
306+ _logger . LogError ( "Failed to compile {0} - {1} (L: {2} | P: {3}) | Removing from project" ,
307+ fileName , diagnosticMessage , line , position ) ;
293308
294309 modified = true ;
295310 compilationResult . Failed ++ ;
296311 }
297312 }
298313 else
299314 {
300- string diagnosticMessage = diagnostic . GetMessage ( ) ;
301315 compilerMessage . Errors ??= new List < CompilerError > ( ) ;
302316 compilerMessage . Errors . Add ( new CompilerError
303317 {
0 commit comments