Skip to content

Commit a0a84e3

Browse files
committed
Avoid adding duplicate suppressors to the host analyzer arrays
1 parent e65c6c8 commit a0a84e3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Workspaces/Remote/ServiceHub/Services/DiagnosticAnalyzer/DiagnosticComputer.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,11 @@ private static (ImmutableArray<DiagnosticAnalyzer> projectAnalyzers, ImmutableAr
506506
if (hostAnalyzerIds.Any())
507507
{
508508
// If any host analyzers are active, make sure to also include any project diagnostic suppressors
509-
hostBuilder.AddRange(projectAnalyzers.WhereAsArray(static a => a is DiagnosticSuppressor));
509+
var projectSuppressors = projectAnalyzers.WhereAsArray(static a => a is DiagnosticSuppressor);
510+
// Make sure to remove any project suppressors already in the host analyzer array so we don't end up with
511+
// duplicates.
512+
hostBuilder.RemoveRange(projectSuppressors);
513+
hostBuilder.AddRange(projectSuppressors);
510514
}
511515

512516
return (projectAnalyzers, hostBuilder.ToImmutableAndClear());
@@ -591,7 +595,13 @@ private async Task<CompilationWithAnalyzersCacheEntry> CreateCompilationWithAnal
591595

592596
var analyzers = reference.GetAnalyzers(_project.Language);
593597
projectAnalyzerBuilder.AddRange(analyzers);
594-
hostAnalyzerBuilder.AddRange(analyzers.WhereAsArray(static a => a is DiagnosticSuppressor));
598+
599+
var projectSuppressors = analyzers.WhereAsArray(static a => a is DiagnosticSuppressor);
600+
// Make sure to remove any project suppressors already in the host analyzer array so we don't end up with
601+
// duplicates.
602+
hostAnalyzerBuilder.RemoveRange(projectSuppressors);
603+
hostAnalyzerBuilder.AddRange(projectSuppressors);
604+
595605
analyzerMapBuilder.AppendAnalyzerMap(analyzers);
596606
}
597607

0 commit comments

Comments
 (0)