@@ -94,7 +94,7 @@ private static void HandleCompilationStart(CompilationStartAnalysisContext conte
9494
9595 private class AnalyzerContext
9696 {
97- private List < Diagnostic > reportedDiagnostics = new List < Diagnostic > ( ) ;
97+ private readonly List < Diagnostic > reportedDiagnostics = new List < Diagnostic > ( ) ;
9898
9999 public void HandleBlock ( SyntaxNodeAnalysisContext context )
100100 {
@@ -230,30 +230,34 @@ private void ReportDiagnostic(SyntaxNodeAnalysisContext context, Location locati
230230 {
231231 Diagnostic newDiagnostic ;
232232
233- var locationLine = location . GetLineSpan ( ) . StartLinePosition . Line ;
234- var notFirstDiagnosticOnLine = this . reportedDiagnostics . Any ( rd => ( rd . Severity != DiagnosticSeverity . Hidden ) && ( rd . Location . GetLineSpan ( ) . StartLinePosition . Line == locationLine ) ) ;
235-
236- if ( alwaysReportAsHidden || notFirstDiagnosticOnLine )
237- {
238- newDiagnostic = Diagnostic . Create (
239- Descriptor . Id ,
240- Descriptor . Category ,
241- Descriptor . MessageFormat ,
242- DiagnosticSeverity . Hidden ,
243- Descriptor . DefaultSeverity ,
244- Descriptor . IsEnabledByDefault ,
245- 1 ,
246- Descriptor . Title ,
247- Descriptor . Description ,
248- Descriptor . HelpLinkUri ,
249- location ) ;
250- }
251- else
233+ lock ( this . reportedDiagnostics )
252234 {
253- newDiagnostic = Diagnostic . Create ( Descriptor , location ) ;
235+ var locationLine = location . GetLineSpan ( ) . StartLinePosition . Line ;
236+ var notFirstDiagnosticOnLine = this . reportedDiagnostics . Any ( rd => ( rd . Severity != DiagnosticSeverity . Hidden ) && ( rd . Location . GetLineSpan ( ) . StartLinePosition . Line == locationLine ) ) ;
237+
238+ if ( alwaysReportAsHidden || notFirstDiagnosticOnLine )
239+ {
240+ newDiagnostic = Diagnostic . Create (
241+ Descriptor . Id ,
242+ Descriptor . Category ,
243+ Descriptor . MessageFormat ,
244+ DiagnosticSeverity . Hidden ,
245+ Descriptor . DefaultSeverity ,
246+ Descriptor . IsEnabledByDefault ,
247+ 1 ,
248+ Descriptor . Title ,
249+ Descriptor . Description ,
250+ Descriptor . HelpLinkUri ,
251+ location ) ;
252+ }
253+ else
254+ {
255+ newDiagnostic = Diagnostic . Create ( Descriptor , location ) ;
256+ }
257+
258+ this . reportedDiagnostics . Add ( newDiagnostic ) ;
254259 }
255260
256- this . reportedDiagnostics . Add ( newDiagnostic ) ;
257261 context . ReportDiagnostic ( newDiagnostic ) ;
258262 }
259263 }
0 commit comments