|
13 | 13 | using Microsoft.CodeAnalysis.Host; |
14 | 14 | using Microsoft.CodeAnalysis.Host.Mef; |
15 | 15 | using Microsoft.CodeAnalysis.Options; |
| 16 | +using Microsoft.CodeAnalysis.Shared.Extensions; |
16 | 17 | using Microsoft.CodeAnalysis.Shared.TestHooks; |
17 | 18 | using Microsoft.CodeAnalysis.SolutionCrawler; |
18 | 19 | using Microsoft.CodeAnalysis.Workspaces.Diagnostics; |
| 20 | +using Roslyn.Utilities; |
19 | 21 |
|
20 | 22 | namespace Microsoft.CodeAnalysis.Diagnostics; |
21 | 23 |
|
@@ -124,20 +126,40 @@ private ImmutableArray<DiagnosticAnalyzer> GetDiagnosticAnalyzers( |
124 | 126 | ImmutableHashSet<string>? diagnosticIds, |
125 | 127 | Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer) |
126 | 128 | { |
127 | | - var analyzersForProject = GetProjectAnalyzers(project); |
128 | | - var analyzers = analyzersForProject.WhereAsArray(a => ShouldIncludeAnalyzer(project, a)); |
| 129 | + var (hostAnalyzers, projectAnalyzers) = GetProjectAnalyzersPair(project); |
| 130 | + return [ |
| 131 | + .. hostAnalyzers.WhereAsArray(a => ShouldIncludeAnalyzer(project, a, isHostAnalyzer: true)), |
| 132 | + .. projectAnalyzers.WhereAsArray(a => ShouldIncludeAnalyzer(project, a, isHostAnalyzer: false))]; |
129 | 133 |
|
130 | | - return analyzers; |
131 | | - |
132 | | - bool ShouldIncludeAnalyzer(Project project, DiagnosticAnalyzer analyzer) |
| 134 | + bool ShouldIncludeAnalyzer(Project project, DiagnosticAnalyzer analyzer, bool isHostAnalyzer) |
133 | 135 | { |
134 | 136 | if (!DocumentAnalysisExecutor.IsAnalyzerEnabledForProject(analyzer, project, this._globalOptions)) |
135 | 137 | return false; |
136 | 138 |
|
137 | 139 | if (shouldIncludeAnalyzer != null && !shouldIncludeAnalyzer(analyzer)) |
138 | 140 | return false; |
139 | 141 |
|
140 | | - if (diagnosticIds != null && _analyzerInfoCache.GetDiagnosticDescriptors(analyzer).All(d => !diagnosticIds.Contains(d.Id))) |
| 142 | + var descriptors = _analyzerInfoCache.GetDiagnosticDescriptors(analyzer); |
| 143 | + |
| 144 | + if (diagnosticIds != null && descriptors.All(d => !diagnosticIds.Contains(d.Id))) |
| 145 | + return false; |
| 146 | + |
| 147 | + var analyzerConfigOptions = project.GetAnalyzerConfigOptions(); |
| 148 | + |
| 149 | + var allDescriptorsAreHidden = project.CompilationOptions != null && descriptors.All(static (d, arg) => |
| 150 | + { |
| 151 | + var effectiveSeverity = d.GetEffectiveSeverity( |
| 152 | + arg.CompilationOptions, |
| 153 | + arg.isHostAnalyzer |
| 154 | + ? arg.analyzerConfigOptions?.ConfigOptionsWithFallback |
| 155 | + : arg.analyzerConfigOptions?.ConfigOptionsWithoutFallback, |
| 156 | + arg.analyzerConfigOptions?.TreeOptions); |
| 157 | + |
| 158 | + return effectiveSeverity == ReportDiagnostic.Hidden; |
| 159 | + }, |
| 160 | + (project.CompilationOptions, isHostAnalyzer, analyzerConfigOptions)); |
| 161 | + |
| 162 | + if (allDescriptorsAreHidden) |
141 | 163 | return false; |
142 | 164 |
|
143 | 165 | return true; |
|
0 commit comments