Merge pull request #20849 from michaelnebel/csharp/addcompilationerrorstodebuglogbmn

C#: Add compilation errors to the debug log in BMN.
This commit is contained in:
Michael Nebel
2025-11-18 11:20:27 +01:00
committed by GitHub
4 changed files with 32 additions and 13 deletions

View File

@@ -360,5 +360,22 @@ namespace Semmle.Extraction.CSharp
return versionString.InformationalVersion;
}
}
private static readonly HashSet<string> errorsToIgnore = new HashSet<string>
{
"CS7027", // Code signing failure
"CS1589", // XML referencing not supported
"CS1569" // Error writing XML documentation
};
/// <summary>
/// Retrieves the diagnostics from the compilation, filtering out those that should be ignored.
/// </summary>
protected List<Diagnostic> GetFilteredDiagnostics() =>
compilation is not null
? compilation.GetDiagnostics()
.Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id))
.ToList()
: [];
}
}

View File

@@ -13,6 +13,14 @@ namespace Semmle.Extraction.CSharp
{
}
private void LogDiagnostics()
{
foreach (var error in GetFilteredDiagnostics())
{
Logger.LogDebug($" Compilation error: {error}");
}
}
public void Initialize(string outputPath, IEnumerable<(string, string)> compilationInfos, CSharpCompilation compilationIn, CommonOptions options)
{
compilation = compilationIn;
@@ -20,6 +28,7 @@ namespace Semmle.Extraction.CSharp
this.options = options;
LogExtractorInfo();
SetReferencePaths();
LogDiagnostics();
}
}
}

View File

@@ -136,11 +136,7 @@ namespace Semmle.Extraction.CSharp
private int LogDiagnostics()
{
var filteredDiagnostics = compilation!
.GetDiagnostics()
.Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id))
.ToList();
var filteredDiagnostics = GetFilteredDiagnostics();
foreach (var error in filteredDiagnostics)
{
Logger.LogError($" Compilation error: {error}");
@@ -148,7 +144,7 @@ namespace Semmle.Extraction.CSharp
if (filteredDiagnostics.Count != 0)
{
foreach (var reference in compilation.References)
foreach (var reference in compilation!.References)
{
Logger.LogInfo($" Resolved reference {reference.Display}");
}
@@ -156,12 +152,5 @@ namespace Semmle.Extraction.CSharp
return filteredDiagnostics.Count;
}
private static readonly HashSet<string> errorsToIgnore = new HashSet<string>
{
"CS7027", // Code signing failure
"CS1589", // XML referencing not supported
"CS1569" // Error writing XML documentation
};
}
}

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Compilation errors are now included in the debug log when using build-mode none.