@@ -22,6 +22,7 @@ internal static class FixAllContextHelper
2222
2323 private static readonly Func < CompilationWithAnalyzers , SyntaxTree , CancellationToken , Task < ImmutableArray < Diagnostic > > > GetAnalyzerSyntaxDiagnosticsAsync ;
2424 private static readonly Func < CompilationWithAnalyzers , SemanticModel , TextSpan ? , CancellationToken , Task < ImmutableArray < Diagnostic > > > GetAnalyzerSemanticDiagnosticsAsync ;
25+ private static readonly Func < CompilationWithAnalyzers , ImmutableArray < DiagnosticAnalyzer > , CancellationToken , Task < ImmutableArray < Diagnostic > > > GetAnalyzerCompilationDiagnosticsAsync ;
2526
2627 static FixAllContextHelper ( )
2728 {
@@ -34,6 +35,9 @@ static FixAllContextHelper()
3435
3536 methodInfo = typeof ( CompilationWithAnalyzers ) . GetRuntimeMethod ( nameof ( GetAnalyzerSemanticDiagnosticsAsync ) , new [ ] { typeof ( SemanticModel ) , typeof ( TextSpan ? ) , typeof ( CancellationToken ) } ) ;
3637 GetAnalyzerSemanticDiagnosticsAsync = ( Func < CompilationWithAnalyzers , SemanticModel , TextSpan ? , CancellationToken , Task < ImmutableArray < Diagnostic > > > ) methodInfo ? . CreateDelegate ( typeof ( Func < CompilationWithAnalyzers , SemanticModel , TextSpan ? , CancellationToken , Task < ImmutableArray < Diagnostic > > > ) ) ;
38+
39+ methodInfo = typeof ( CompilationWithAnalyzers ) . GetRuntimeMethod ( nameof ( GetAnalyzerCompilationDiagnosticsAsync ) , new [ ] { typeof ( ImmutableArray < DiagnosticAnalyzer > ) , typeof ( CancellationToken ) } ) ;
40+ GetAnalyzerCompilationDiagnosticsAsync = ( Func < CompilationWithAnalyzers , ImmutableArray < DiagnosticAnalyzer > , CancellationToken , Task < ImmutableArray < Diagnostic > > > ) methodInfo ? . CreateDelegate ( typeof ( Func < CompilationWithAnalyzers , ImmutableArray < DiagnosticAnalyzer > , CancellationToken , Task < ImmutableArray < Diagnostic > > > ) ) ;
3741 }
3842 }
3943
@@ -126,7 +130,7 @@ public static async Task<ImmutableDictionary<Project, ImmutableArray<Diagnostic>
126130 return ImmutableDictionary < Project , ImmutableArray < Diagnostic > > . Empty ;
127131 }
128132
129- public static async Task < ImmutableArray < Diagnostic > > GetAllDiagnosticsAsync ( Compilation compilation , CompilationWithAnalyzers compilationWithAnalyzers , IEnumerable < Document > documents , bool includeCompilerDiagnostics , CancellationToken cancellationToken )
133+ public static async Task < ImmutableArray < Diagnostic > > GetAllDiagnosticsAsync ( Compilation compilation , CompilationWithAnalyzers compilationWithAnalyzers , ImmutableArray < DiagnosticAnalyzer > analyzers , IEnumerable < Document > documents , bool includeCompilerDiagnostics , CancellationToken cancellationToken )
130134 {
131135 if ( GetAnalyzerSyntaxDiagnosticsAsync == null || GetAnalyzerSemanticDiagnosticsAsync == null )
132136 {
@@ -138,9 +142,7 @@ public static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Comp
138142 compilationWithAnalyzers . Compilation . GetDeclarationDiagnostics ( cancellationToken ) ;
139143
140144 // Note that the following loop to obtain syntax and semantic diagnostics for each document cannot operate
141- // on parallel due to our use of a single CompilationWithAnalyzers instance. Also note that the following
142- // code is not sufficient for cases where analyzers register compilation end actions. However, this project
143- // does not currently contain any such analyzers.
145+ // on parallel due to our use of a single CompilationWithAnalyzers instance.
144146 var diagnostics = ImmutableArray < Diagnostic > . Empty ;
145147 foreach ( var document in documents )
146148 {
@@ -153,6 +155,11 @@ public static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Comp
153155 diagnostics = diagnostics . AddRange ( semanticDiagnostics ) ;
154156 }
155157
158+ foreach ( var analyzer in analyzers )
159+ {
160+ diagnostics = diagnostics . AddRange ( await GetAnalyzerCompilationDiagnosticsAsync ( compilationWithAnalyzers , ImmutableArray . Create ( analyzer ) , cancellationToken ) . ConfigureAwait ( false ) ) ;
161+ }
162+
156163 if ( includeCompilerDiagnostics )
157164 {
158165 // This is the special handling for cases where code fixes operate on warnings produced by the C#
@@ -238,7 +245,7 @@ private static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Fix
238245 // GetDeclarationDiagnostics workaround for dotnet/roslyn#7446 a single time, rather than once per document.
239246 var compilation = await project . GetCompilationAsync ( fixAllContext . CancellationToken ) . ConfigureAwait ( false ) ;
240247 var compilationWithAnalyzers = compilation . WithAnalyzers ( analyzers , project . AnalyzerOptions , fixAllContext . CancellationToken ) ;
241- ImmutableArray < Diagnostic > diagnostics = await GetAllDiagnosticsAsync ( compilation , compilationWithAnalyzers , project . Documents , includeCompilerDiagnostics , fixAllContext . CancellationToken ) . ConfigureAwait ( false ) ;
248+ ImmutableArray < Diagnostic > diagnostics = await GetAllDiagnosticsAsync ( compilation , compilationWithAnalyzers , analyzers , project . Documents , includeCompilerDiagnostics , fixAllContext . CancellationToken ) . ConfigureAwait ( false ) ;
242249
243250 // Make sure to filter the results to the set requested for the Fix All operation, since analyzers can
244251 // report diagnostics with different IDs.
0 commit comments