Skip to content

Commit ffd763a

Browse files
Remove the ProjectDiagnosticAnalyzer type (#77899)
Currently 'draft' as this depends on TypeScript having moved entirely to LSP pull diagnostics. TS pr to move them off of us is here: https://devdiv.visualstudio.com/DevDiv/_git/TypeScript-VS/pullrequest/623063
2 parents ff34293 + 9cb402c commit ffd763a

15 files changed

+35
-244
lines changed

src/EditorFeatures/Test/Diagnostics/DiagnosticAnalyzerServiceTests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public async Task TestHostAnalyzerErrorNotLeaking()
239239

240240
var solution = workspace.CurrentSolution;
241241

242-
var analyzerReference = new AnalyzerImageReference([new LeakDocumentAnalyzer(), new LeakProjectAnalyzer()]);
242+
var analyzerReference = new AnalyzerImageReference([new LeakDocumentAnalyzer()]);
243243

244244
var globalOptions = GetGlobalOptions(workspace);
245245
globalOptions.SetGlobalOption(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp, BackgroundAnalysisScope.FullSolution);
@@ -913,13 +913,6 @@ public override Task<ImmutableArray<Diagnostic>> AnalyzeSemanticsAsync(Document
913913
=> SpecializedTasks.Default<ImmutableArray<Diagnostic>>();
914914
}
915915

916-
private sealed class LeakProjectAnalyzer : ProjectDiagnosticAnalyzer
917-
{
918-
private static readonly DiagnosticDescriptor s_rule = new DiagnosticDescriptor("project", "test", "test", "test", DiagnosticSeverity.Error, isEnabledByDefault: true);
919-
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [s_rule];
920-
public override Task<ImmutableArray<Diagnostic>> AnalyzeProjectAsync(Project project, CancellationToken cancellationToken) => SpecializedTasks.Default<ImmutableArray<Diagnostic>>();
921-
}
922-
923916
[DiagnosticAnalyzer(LanguageNames.CSharp)]
924917
private sealed class NamedTypeAnalyzer : DiagnosticAnalyzer
925918
{

src/Features/Core/Portable/Diagnostics/DiagnosticAnalyzerExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics;
1414
internal static class DiagnosticAnalyzerExtensions
1515
{
1616
public static bool IsWorkspaceDiagnosticAnalyzer(this DiagnosticAnalyzer analyzer)
17-
=> analyzer is DocumentDiagnosticAnalyzer
18-
|| analyzer is ProjectDiagnosticAnalyzer;
17+
=> analyzer is DocumentDiagnosticAnalyzer;
1918

2019
public static bool IsBuiltInAnalyzer(this DiagnosticAnalyzer analyzer)
2120
=> analyzer is IBuiltInAnalyzer || analyzer.IsWorkspaceDiagnosticAnalyzer() || analyzer.IsCompilerAnalyzer();

src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptDiagnosticAnalyzerImplementation.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDiagnosticAnalyzerLanguageService.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptDocumentDiagnosticAnalyzer.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Features/Core/Portable/ExternalAccess/VSTypeScript/VSTypeScriptProjectDiagnosticAnalyzer.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor_Helpers.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,39 +119,6 @@ public static async Task<ImmutableArray<Diagnostic>> ComputeDocumentDiagnosticAn
119119
return diagnostics;
120120
}
121121

122-
public static async Task<ImmutableArray<Diagnostic>> ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(
123-
ProjectDiagnosticAnalyzer analyzer,
124-
Project project,
125-
Compilation? compilation,
126-
CancellationToken cancellationToken)
127-
{
128-
cancellationToken.ThrowIfCancellationRequested();
129-
130-
ImmutableArray<Diagnostic> diagnostics;
131-
try
132-
{
133-
diagnostics = (await analyzer.AnalyzeProjectAsync(project, cancellationToken).ConfigureAwait(false)).NullToEmpty();
134-
#if DEBUG
135-
// since all ProjectDiagnosticAnalyzers are from internal users, we only do debug check. also this can be expensive at runtime
136-
// since it requires await. if we find any offender through NFW, we should be able to fix those since all those should
137-
// from intern teams.
138-
await VerifyDiagnosticLocationsAsync(diagnostics, project, cancellationToken).ConfigureAwait(false);
139-
#endif
140-
}
141-
catch (Exception e) when (!IsCanceled(e, cancellationToken))
142-
{
143-
diagnostics = [CreateAnalyzerExceptionDiagnostic(analyzer, e)];
144-
}
145-
146-
// Apply filtering from compilation options (source suppressions, ruleset, etc.)
147-
if (compilation != null)
148-
{
149-
diagnostics = CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilation).ToImmutableArrayOrEmpty();
150-
}
151-
152-
return diagnostics;
153-
}
154-
155122
private static bool IsCanceled(Exception ex, CancellationToken cancellationToken)
156123
=> (ex as OperationCanceledException)?.CancellationToken == cancellationToken;
157124

src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.Executor.cs

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ private sealed partial class DiagnosticIncrementalAnalyzer
2828
private async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> ComputeDiagnosticAnalysisResultsAsync(
2929
CompilationWithAnalyzersPair? compilationWithAnalyzers,
3030
Project project,
31-
ImmutableArray<DiagnosticAnalyzer> analyzers,
31+
ImmutableArray<DocumentDiagnosticAnalyzer> analyzers,
3232
CancellationToken cancellationToken)
3333
{
3434
using (Logger.LogBlock(FunctionId.Diagnostics_ProjectDiagnostic, GetProjectLogMessage, project, analyzers, cancellationToken))
3535
{
3636
try
3737
{
38-
var result = await ComputeDiagnosticsForIDEAnalyzersAsync(analyzers).ConfigureAwait(false);
38+
var result = await ComputeDiagnosticsForAnalyzersAsync(analyzers).ConfigureAwait(false);
3939

4040
// If project is not loaded successfully, get rid of any semantic errors from compiler analyzer.
4141
// 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
8686
// Calculate all diagnostics for a given project using analyzers referenced by the project and specified IDE analyzers.
8787
// </summary>
8888
async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> ComputeDiagnosticsForAnalyzersAsync(
89-
ImmutableArray<DiagnosticAnalyzer> ideAnalyzers)
89+
ImmutableArray<DocumentDiagnosticAnalyzer> ideAnalyzers)
9090
{
9191
try
9292
{
@@ -107,7 +107,6 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
107107
}
108108

109109
// check whether there is IDE specific project diagnostic analyzer
110-
Debug.Assert(ideAnalyzers.All(a => a is ProjectDiagnosticAnalyzer or DocumentDiagnosticAnalyzer));
111110
return await MergeProjectDiagnosticAnalyzerDiagnosticsAsync(ideAnalyzers, result).ConfigureAwait(false);
112111
}
113112
catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e, cancellationToken))
@@ -116,67 +115,42 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Co
116115
}
117116
}
118117

119-
async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> ComputeDiagnosticsForIDEAnalyzersAsync(
120-
ImmutableArray<DiagnosticAnalyzer> analyzers)
121-
{
122-
try
123-
{
124-
var ideAnalyzers = analyzers.WhereAsArray(a => a is ProjectDiagnosticAnalyzer or 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-
134118
async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> MergeProjectDiagnosticAnalyzerDiagnosticsAsync(
135-
ImmutableArray<DiagnosticAnalyzer> ideAnalyzers,
119+
ImmutableArray<DocumentDiagnosticAnalyzer> ideAnalyzers,
136120
ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult> result)
137121
{
138122
try
139123
{
140124
var compilation = compilationWithAnalyzers?.HostCompilation;
141125

142-
foreach (var analyzer in ideAnalyzers)
126+
foreach (var documentAnalyzer in ideAnalyzers)
143127
{
144128
var builder = new DiagnosticAnalysisResultBuilder(project);
145129

146-
switch (analyzer)
130+
foreach (var textDocument in project.AdditionalDocuments.Concat(project.Documents))
147131
{
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;
170-
171-
case ProjectDiagnosticAnalyzer projectAnalyzer:
172-
builder.AddCompilationDiagnostics(await DocumentAnalysisExecutor.ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(projectAnalyzer, project, compilation, cancellationToken).ConfigureAwait(false));
173-
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+
}
174148
}
175149

176150
// merge the result to existing one.
177151
// there can be existing one from compiler driver with empty set. overwrite it with
178152
// ide one.
179-
result = result.SetItem(analyzer, DiagnosticAnalysisResult.CreateFromBuilder(builder));
153+
result = result.SetItem(documentAnalyzer, DiagnosticAnalysisResult.CreateFromBuilder(builder));
180154
}
181155

182156
return result;

src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.HostAnalyzerInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ private static int GetPriority(DiagnosticAnalyzer state)
144144
return state switch
145145
{
146146
DocumentDiagnosticAnalyzer analyzer => analyzer.Priority,
147-
ProjectDiagnosticAnalyzer analyzer => Math.Max(0, analyzer.Priority),
148147
_ => RegularDiagnosticAnalyzerPriority,
149148
};
150149
}

src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DiagnosticIncrementalAnalyzer(
4848
public Task<ImmutableArray<DiagnosticAnalyzer>> GetAnalyzersForTestingPurposesOnlyAsync(Project project, CancellationToken cancellationToken)
4949
=> _stateManager.GetOrCreateAnalyzersAsync(project.Solution.SolutionState, project.State, cancellationToken);
5050

51-
private static string GetProjectLogMessage(Project project, ImmutableArray<DiagnosticAnalyzer> analyzers)
51+
private static string GetProjectLogMessage(Project project, ImmutableArray<DocumentDiagnosticAnalyzer> analyzers)
5252
=> $"project: ({project.Id}), ({string.Join(Environment.NewLine, analyzers.Select(a => a.ToString()))})";
5353
}
5454
}

src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ async Task<ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>> Ge
130130
var compilation = await GetOrCreateCompilationWithAnalyzersAsync(
131131
project, analyzers, hostAnalyzerInfo, AnalyzerService.CrashOnAnalyzerException, cancellationToken).ConfigureAwait(false);
132132

133-
var result = await ComputeDiagnosticAnalysisResultsAsync(compilation, project, analyzers, cancellationToken).ConfigureAwait(false);
133+
var result = await ComputeDiagnosticAnalysisResultsAsync(
134+
compilation, project, [.. analyzers.OfType<DocumentDiagnosticAnalyzer>()], cancellationToken).ConfigureAwait(false);
134135
return result;
135136
}
136137

src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public async Task<ImmutableArray<DiagnosticData>> ForceAnalyzeProjectAsync(Proje
8686
var compilationWithAnalyzers = await GetOrCreateCompilationWithAnalyzersAsync(
8787
project, fullSolutionAnalysisAnalyzers, hostAnalyzerInfo, AnalyzerService.CrashOnAnalyzerException, cancellationToken).ConfigureAwait(false);
8888

89-
var projectAnalysisData = await ComputeDiagnosticAnalysisResultsAsync(compilationWithAnalyzers, project, fullSolutionAnalysisAnalyzers, cancellationToken).ConfigureAwait(false);
89+
var projectAnalysisData = await ComputeDiagnosticAnalysisResultsAsync(
90+
compilationWithAnalyzers, project, [.. fullSolutionAnalysisAnalyzers.OfType<DocumentDiagnosticAnalyzer>()], cancellationToken).ConfigureAwait(false);
9091
return (checksum, fullSolutionAnalysisAnalyzers, projectAnalysisData);
9192
}
9293

src/Workspaces/Core/Portable/Diagnostics/DiagnosticAnalyzerExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public static DiagnosticAnalyzerCategory GetDiagnosticAnalyzerCategory(this Diag
1111
{
1212
FileContentLoadAnalyzer => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis,
1313
DocumentDiagnosticAnalyzer => DiagnosticAnalyzerCategory.SyntaxTreeWithoutSemanticsAnalysis | DiagnosticAnalyzerCategory.SemanticDocumentAnalysis,
14-
ProjectDiagnosticAnalyzer => DiagnosticAnalyzerCategory.None,
1514
IBuiltInAnalyzer builtInAnalyzer => builtInAnalyzer.GetAnalyzerCategory(),
1615

1716
// Compiler analyzer supports syntax diagnostics, span-based semantic diagnostics and project level diagnostics.

0 commit comments

Comments
 (0)