@@ -28,14 +28,14 @@ private sealed partial class DiagnosticIncrementalAnalyzer
28
28
private async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > ComputeDiagnosticAnalysisResultsAsync (
29
29
CompilationWithAnalyzersPair ? compilationWithAnalyzers ,
30
30
Project project ,
31
- ImmutableArray < DiagnosticAnalyzer > analyzers ,
31
+ ImmutableArray < DocumentDiagnosticAnalyzer > analyzers ,
32
32
CancellationToken cancellationToken )
33
33
{
34
34
using ( Logger . LogBlock ( FunctionId . Diagnostics_ProjectDiagnostic , GetProjectLogMessage , project , analyzers , cancellationToken ) )
35
35
{
36
36
try
37
37
{
38
- var result = await ComputeDiagnosticsForIDEAnalyzersAsync ( analyzers ) . ConfigureAwait ( false ) ;
38
+ var result = await ComputeDiagnosticsForAnalyzersAsync ( analyzers ) . ConfigureAwait ( false ) ;
39
39
40
40
// If project is not loaded successfully, get rid of any semantic errors from compiler analyzer.
41
41
// 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
86
86
// Calculate all diagnostics for a given project using analyzers referenced by the project and specified IDE analyzers.
87
87
// </summary>
88
88
async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > ComputeDiagnosticsForAnalyzersAsync (
89
- ImmutableArray < DiagnosticAnalyzer > ideAnalyzers )
89
+ ImmutableArray < DocumentDiagnosticAnalyzer > ideAnalyzers )
90
90
{
91
91
try
92
92
{
@@ -107,7 +107,6 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
107
107
}
108
108
109
109
// check whether there is IDE specific project diagnostic analyzer
110
- Debug . Assert ( ideAnalyzers . All ( a => a is DocumentDiagnosticAnalyzer ) ) ;
111
110
return await MergeProjectDiagnosticAnalyzerDiagnosticsAsync ( ideAnalyzers , result ) . ConfigureAwait ( false ) ;
112
111
}
113
112
catch ( Exception e ) when ( FatalError . ReportAndPropagateUnlessCanceled ( e , cancellationToken ) )
@@ -116,63 +115,42 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
116
115
}
117
116
}
118
117
119
- async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > ComputeDiagnosticsForIDEAnalyzersAsync (
120
- ImmutableArray < DiagnosticAnalyzer > analyzers )
121
- {
122
- try
123
- {
124
- var ideAnalyzers = analyzers . WhereAsArray ( a => a is 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
-
134
118
async Task < ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > > MergeProjectDiagnosticAnalyzerDiagnosticsAsync (
135
- ImmutableArray < DiagnosticAnalyzer > ideAnalyzers ,
119
+ ImmutableArray < DocumentDiagnosticAnalyzer > ideAnalyzers ,
136
120
ImmutableDictionary < DiagnosticAnalyzer , DiagnosticAnalysisResult > result )
137
121
{
138
122
try
139
123
{
140
124
var compilation = compilationWithAnalyzers ? . HostCompilation ;
141
125
142
- foreach ( var analyzer in ideAnalyzers )
126
+ foreach ( var documentAnalyzer in ideAnalyzers )
143
127
{
144
128
var builder = new DiagnosticAnalysisResultBuilder ( project ) ;
145
129
146
- switch ( analyzer )
130
+ foreach ( var textDocument in project . AdditionalDocuments . Concat ( project . Documents ) )
147
131
{
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 ;
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
+ }
170
148
}
171
149
172
150
// merge the result to existing one.
173
151
// there can be existing one from compiler driver with empty set. overwrite it with
174
152
// ide one.
175
- result = result . SetItem ( analyzer , DiagnosticAnalysisResult . CreateFromBuilder ( builder ) ) ;
153
+ result = result . SetItem ( documentAnalyzer , DiagnosticAnalysisResult . CreateFromBuilder ( builder ) ) ;
176
154
}
177
155
178
156
return result ;
0 commit comments