@@ -28,14 +28,14 @@ private sealed partial class DiagnosticIncrementalAnalyzer
2828 private async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > ComputeDiagnosticAnalysisResultsAsync (
2929 CompilationWithAnalyzersPair ? compilationWithAnalyzers ,
3030 Project project ,
31- ImmutableArray < DiagnosticAnalyzer > analyzers ,
31+ ImmutableArray < DocumentDiagnosticAnalyzer > analyzers ,
3232 CancellationToken cancellationToken )
3333 {
3434 using ( Logger . LogBlock ( FunctionId . Diagnostics_ProjectDiagnostic , GetProjectLogMessage , project , analyzers , cancellationToken ) )
3535 {
3636 try
3737 {
38- var result = await ComputeDiagnosticsForIDEAnalyzersAsync ( analyzers ) . ConfigureAwait ( false ) ;
38+ var result = await ComputeDiagnosticsForAnalyzersAsync ( analyzers ) . ConfigureAwait ( false ) ;
3939
4040 // If project is not loaded successfully, get rid of any semantic errors from compiler analyzer.
4141 // Note: In the past when project was not loaded successfully we did not run any analyzers on the project.
@@ -86,7 +86,7 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Re
8686 // Calculate all diagnostics for a given project using analyzers referenced by the project and specified IDE analyzers.
8787 // </summary>
8888 async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > ComputeDiagnosticsForAnalyzersAsync (
89- ImmutableArray < DiagnosticAnalyzer > ideAnalyzers )
89+ ImmutableArray < DocumentDiagnosticAnalyzer > ideAnalyzers )
9090 {
9191 try
9292 {
@@ -107,7 +107,6 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
107107 }
108108
109109 // check whether there is IDE specific project diagnostic analyzer
110- Debug . Assert ( ideAnalyzers . All ( a => a is ProjectDiagnosticAnalyzer or DocumentDiagnosticAnalyzer ) ) ;
111110 return await MergeProjectDiagnosticAnalyzerDiagnosticsAsync ( ideAnalyzers , result ) . ConfigureAwait ( false ) ;
112111 }
113112 catch ( Exception e ) when ( FatalError . ReportAndPropagateUnlessCanceled ( e , cancellationToken ) )
@@ -116,67 +115,42 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
116115 }
117116 }
118117
119- async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > ComputeDiagnosticsForIDEAnalyzersAsync (
120- ImmutableArray < DiagnosticAnalyzer > analyzers )
121- {
122- try
123- {
124- var ideAnalyzers = analyzers . WhereAsArray ( a => a is ProjectDiagnosticAnalyzer or DocumentDiagnosticAnalyzer ) ;
125-
126- return await ComputeDiagnosticsForAnalyzersAsync ( ideAnalyzers ) . ConfigureAwait ( false ) ;
127- }
128- catch ( Exception e ) when ( FatalError . ReportAndPropagateUnlessCanceled ( e , cancellationToken ) )
129- {
130- throw ExceptionUtilities . Unreachable ( ) ;
131- }
132- }
133-
134118 async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > MergeProjectDiagnosticAnalyzerDiagnosticsAsync (
135- ImmutableArray < DiagnosticAnalyzer > ideAnalyzers ,
119+ ImmutableArray < DocumentDiagnosticAnalyzer > ideAnalyzers ,
136120 ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > result )
137121 {
138122 try
139123 {
140124 var compilation = compilationWithAnalyzers ? . HostCompilation ;
141125
142- foreach ( var analyzer in ideAnalyzers )
126+ foreach ( var documentAnalyzer in ideAnalyzers )
143127 {
144128 var builder = new DiagnosticAnalysisResultBuilder ( project ) ;
145129
146- switch ( analyzer )
130+ foreach ( var textDocument in project . AdditionalDocuments . Concat ( project . Documents ) )
147131 {
148- case DocumentDiagnosticAnalyzer documentAnalyzer :
149- foreach ( var textDocument in project . AdditionalDocuments . Concat ( project . Documents ) )
150- {
151- var tree = textDocument is Document document
152- ? await document . GetSyntaxTreeAsync ( cancellationToken ) . ConfigureAwait ( false )
153- : null ;
154- var syntaxDiagnostics = await DocumentAnalysisExecutor . ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync ( documentAnalyzer , textDocument , AnalysisKind . Syntax , compilation , tree , cancellationToken ) . ConfigureAwait ( false ) ;
155- var semanticDiagnostics = await DocumentAnalysisExecutor . ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync ( documentAnalyzer , textDocument , AnalysisKind . Semantic , compilation , tree , cancellationToken ) . ConfigureAwait ( false ) ;
156-
157- if ( tree != null )
158- {
159- builder . AddSyntaxDiagnostics ( tree , syntaxDiagnostics ) ;
160- builder . AddSemanticDiagnostics ( tree , semanticDiagnostics ) ;
161- }
162- else
163- {
164- builder . AddExternalSyntaxDiagnostics ( textDocument . Id , syntaxDiagnostics ) ;
165- builder . AddExternalSemanticDiagnostics ( textDocument . Id , semanticDiagnostics ) ;
166- }
167- }
168-
169- break ;
170-
171- case ProjectDiagnosticAnalyzer projectAnalyzer :
172- builder . AddCompilationDiagnostics ( await DocumentAnalysisExecutor . ComputeProjectDiagnosticAnalyzerDiagnosticsAsync ( projectAnalyzer , project , compilation , cancellationToken ) . ConfigureAwait ( false ) ) ;
173- break ;
132+ var tree = textDocument is Document document
133+ ? await document . GetSyntaxTreeAsync ( cancellationToken ) . ConfigureAwait ( false )
134+ : null ;
135+ var syntaxDiagnostics = await DocumentAnalysisExecutor . ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync ( documentAnalyzer , textDocument , AnalysisKind . Syntax , compilation , tree , cancellationToken ) . ConfigureAwait ( false ) ;
136+ var semanticDiagnostics = await DocumentAnalysisExecutor . ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync ( documentAnalyzer , textDocument , AnalysisKind . Semantic , compilation , tree , cancellationToken ) . ConfigureAwait ( false ) ;
137+
138+ if ( tree != null )
139+ {
140+ builder . AddSyntaxDiagnostics ( tree , syntaxDiagnostics ) ;
141+ builder . AddSemanticDiagnostics ( tree , semanticDiagnostics ) ;
142+ }
143+ else
144+ {
145+ builder . AddExternalSyntaxDiagnostics ( textDocument . Id , syntaxDiagnostics ) ;
146+ builder . AddExternalSemanticDiagnostics ( textDocument . Id , semanticDiagnostics ) ;
147+ }
174148 }
175149
176150 // merge the result to existing one.
177151 // there can be existing one from compiler driver with empty set. overwrite it with
178152 // ide one.
179- result = result . SetItem ( analyzer , DiagnosticAnalysisResult . CreateFromBuilder ( builder ) ) ;
153+ result = result . SetItem ( documentAnalyzer , DiagnosticAnalysisResult . CreateFromBuilder ( builder ) ) ;
180154 }
181155
182156 return result ;
0 commit comments