Skip to content

Commit

Permalink
Fix #69628 Analyzer summary should show suppressor ID (#72569)
Browse files Browse the repository at this point in the history
* Show suppressor ids in analyser report

* Reuse old test

---------

Co-authored-by: Juan C. Diaz <juan.diaz@nicklaushealth.org>
  • Loading branch information
juan-carlos-diaz and juan-diaz-at-nicklaus authored Mar 20, 2024
1 parent 98cd097 commit 20f2319
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9353,13 +9353,14 @@ public void ReportAnalyzerOutput()
responseFile: null,
srcDirectory,
new[] { "/reportanalyzer", "/t:library", srcFile.Path },
analyzers: new[] { new WarningDiagnosticAnalyzer() },
analyzers: [new WarningDiagnosticAnalyzer(), new DiagnosticSuppressorForId("Warning01", "Suppressor01")],
generators: new[] { new DoNothingGenerator().AsSourceGenerator() });
var exitCode = csc.Run(outWriter);
Assert.Equal(0, exitCode);
var output = outWriter.ToString();
Assert.Contains(CodeAnalysisResources.AnalyzerExecutionTimeColumnHeader, output, StringComparison.Ordinal);
Assert.Contains($"{nameof(WarningDiagnosticAnalyzer)} (Warning01)", output, StringComparison.Ordinal);
Assert.Contains($"{nameof(DiagnosticSuppressorForId)} (Suppressor01)", output, StringComparison.Ordinal);
Assert.Contains(CodeAnalysisResources.GeneratorNameColumnHeader, output, StringComparison.Ordinal);
Assert.Contains(typeof(DoNothingGenerator).FullName, output, StringComparison.Ordinal);
CleanupAllGeneratedFiles(srcFile.Path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static void ReportAnalyzerExecutionTime(TextWriter consoleOutput, Analyz
executionTime = kvp.Value.TotalSeconds;
percentage = (int)(executionTime * 100 / totalAnalyzerExecutionTime);

var analyzerIds = string.Join(", ", kvp.Key.SupportedDiagnostics.Select(d => d.Id).Distinct().OrderBy(id => id));
var analyzerIds = string.Join(", ", GetSupportedIds(kvp.Key).Distinct().OrderBy(id => id));
var analyzerNameColumn = $" {kvp.Key} ({analyzerIds})";
consoleOutput.WriteLine(GetColumnEntry(executionTime, percentage, analyzerNameColumn, culture));
}
Expand All @@ -102,6 +102,13 @@ private static void ReportAnalyzerExecutionTime(TextWriter consoleOutput, Analyz
}
}

private static IEnumerable<string> GetSupportedIds(DiagnosticAnalyzer analyzer)
=> analyzer switch
{
DiagnosticSuppressor suppressor => suppressor.SupportedSuppressions.Select(s => s.Id),
_ => analyzer.SupportedDiagnostics.Select(d => d.Id),
};

private static void ReportGeneratorExecutionTime(TextWriter consoleOutput, GeneratorDriverTimingInfo driverTimingInfo, CultureInfo culture)
{
if (driverTimingInfo.GeneratorTimes.IsEmpty)
Expand Down

0 comments on commit 20f2319

Please sign in to comment.