@@ -107,7 +107,7 @@ public virtual EditorConfigOptions InitializeEditorConfigOptions(out Diagnostic
107107 private sealed class CompilationAnalyzer
108108 {
109109 private readonly DuplicateDetector _library = new ( ) ;
110- private readonly List < Diagnostic > _diagnostics = [ ] ;
110+ private readonly Diagnostic _configurationError ;
111111 private readonly int _duplicateTokenThreshold ;
112112 private readonly Helper _helper ;
113113 private readonly bool _shouldGenerateExceptionsFile ;
@@ -118,10 +118,7 @@ public CompilationAnalyzer(int duplicateTokenThreshold, Helper helper, bool shou
118118 _duplicateTokenThreshold = duplicateTokenThreshold ;
119119 _helper = helper ;
120120 _shouldGenerateExceptionsFile = shouldGenerateExceptionsFile ;
121- if ( configurationError != null )
122- {
123- _diagnostics . Add ( configurationError ) ;
124- }
121+ _configurationError = configurationError ;
125122 }
126123
127124 private string ToPrettyReference ( FileLinePositionSpan fileSpan )
@@ -163,7 +160,7 @@ public void AnalyzeMethod(SyntaxNodeAnalysisContext obj)
163160 {
164161 Location location = evidence . LocationEnvelope . Contents ( ) ;
165162 Location existingEvidenceLocation = existingEvidence . LocationEnvelope . Contents ( ) ;
166- CreateDuplicateDiagnostic ( location , existingEvidenceLocation , token , methodDeclarationSyntax ) ;
163+ ReportDuplicateDiagnostic ( obj , location , existingEvidenceLocation , token , methodDeclarationSyntax ) ;
167164
168165 // Don't pile on. Move on to the next method.
169166 return ;
@@ -177,7 +174,7 @@ public void AnalyzeMethod(SyntaxNodeAnalysisContext obj)
177174 }
178175 }
179176
180- private void CreateDuplicateDiagnostic ( Location location , Location existingEvidenceLocation , SyntaxToken token , MethodDeclarationSyntax methodDeclarationSyntax )
177+ private void ReportDuplicateDiagnostic ( SyntaxNodeAnalysisContext context , Location location , Location existingEvidenceLocation , SyntaxToken token , MethodDeclarationSyntax methodDeclarationSyntax )
181178 {
182179 // We found a duplicate, but if it's partially duplicated with itself, ignore it.
183180 if ( ! location . SourceSpan . IntersectsWith ( existingEvidenceLocation . SourceSpan ) )
@@ -186,7 +183,7 @@ private void CreateDuplicateDiagnostic(Location location, Location existingEvide
186183 FileLinePositionSpan existingEvidenceLineSpan = existingEvidenceLocation . GetLineSpan ( ) ;
187184 var reference = ToPrettyReference ( existingEvidenceLineSpan ) ;
188185
189- _diagnostics . Add ( Diagnostic . Create ( Rule , location , new List < Location > ( ) { existingEvidenceLocation } , reference , shapeDetails ) ) ;
186+ context . ReportDiagnostic ( Diagnostic . Create ( Rule , location , new List < Location > ( ) { existingEvidenceLocation } , reference , shapeDetails ) ) ;
190187
191188 if ( _shouldGenerateExceptionsFile )
192189 {
@@ -216,14 +213,14 @@ private void CreateExceptionDiagnostic(Exception ex, SyntaxNodeAnalysisContext s
216213 }
217214
218215 Location location = syntaxNodeAnalysisContext . Node . GetLocation ( ) ;
219- _diagnostics . Add ( Diagnostic . Create ( UnhandledExceptionRule , location , result , ex . Message ) ) ;
216+ syntaxNodeAnalysisContext . ReportDiagnostic ( Diagnostic . Create ( UnhandledExceptionRule , location , result , ex . Message ) ) ;
220217 }
221218
222219 public void EndCompilationAction ( CompilationAnalysisContext context )
223220 {
224- foreach ( Diagnostic diagnostic in _diagnostics )
221+ if ( _configurationError != null )
225222 {
226- context . ReportDiagnostic ( diagnostic ) ;
223+ context . ReportDiagnostic ( _configurationError ) ;
227224 }
228225 }
229226
0 commit comments