Skip to content

Commit 1061ea0

Browse files
Merge base and parent type in diagnostic subsystem (#77110)
2 parents 459efff + 66139ef commit 1061ea0

File tree

1 file changed

+19
-36
lines changed

1 file changed

+19
-36
lines changed

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

+19-36
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,35 @@ internal partial class DiagnosticAnalyzerService
1818
private partial class DiagnosticIncrementalAnalyzer
1919
{
2020
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
21-
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken);
21+
=> new DiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken);
2222

2323
public Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken)
24-
=> new IdeLatestDiagnosticGetter(this, solution, projectId, documentId: null, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics: false, includeNonLocalDocumentDiagnostics).GetProjectDiagnosticsAsync(cancellationToken);
24+
=> new DiagnosticGetter(this, solution, projectId, documentId: null, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics: false, includeNonLocalDocumentDiagnostics).GetProjectDiagnosticsAsync(cancellationToken);
2525

26-
private abstract class DiagnosticGetter(
26+
private sealed class DiagnosticGetter(
2727
DiagnosticIncrementalAnalyzer owner,
2828
Solution solution,
2929
ProjectId projectId,
3030
DocumentId? documentId,
31+
ImmutableHashSet<string>? diagnosticIds,
32+
Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer,
3133
bool includeLocalDocumentDiagnostics,
3234
bool includeNonLocalDocumentDiagnostics)
3335
{
34-
protected readonly DiagnosticIncrementalAnalyzer Owner = owner;
35-
36-
protected readonly Solution Solution = solution;
37-
protected readonly ProjectId ProjectId = projectId;
38-
protected readonly DocumentId? DocumentId = documentId;
39-
protected readonly bool IncludeLocalDocumentDiagnostics = includeLocalDocumentDiagnostics;
40-
protected readonly bool IncludeNonLocalDocumentDiagnostics = includeNonLocalDocumentDiagnostics;
36+
private readonly DiagnosticIncrementalAnalyzer Owner = owner;
4137

42-
protected StateManager StateManager => Owner._stateManager;
38+
private readonly Solution Solution = solution;
39+
private readonly ProjectId ProjectId = projectId;
40+
private readonly DocumentId? DocumentId = documentId;
41+
private readonly ImmutableHashSet<string>? _diagnosticIds = diagnosticIds;
42+
private readonly Func<DiagnosticAnalyzer, bool>? _shouldIncludeAnalyzer = shouldIncludeAnalyzer;
43+
private readonly bool IncludeLocalDocumentDiagnostics = includeLocalDocumentDiagnostics;
44+
private readonly bool IncludeNonLocalDocumentDiagnostics = includeNonLocalDocumentDiagnostics;
4345

44-
protected virtual bool ShouldIncludeDiagnostic(DiagnosticData diagnostic) => true;
46+
private StateManager StateManager => Owner._stateManager;
4547

46-
protected abstract Task ProduceDiagnosticsAsync(
47-
Project project, IReadOnlyList<DocumentId> documentIds, bool includeProjectNonLocalResult, ArrayBuilder<DiagnosticData> builder, CancellationToken cancellationToken);
48+
private bool ShouldIncludeDiagnostic(DiagnosticData diagnostic)
49+
=> _diagnosticIds == null || _diagnosticIds.Contains(diagnostic.Id);
4850

4951
public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(CancellationToken cancellationToken)
5052
{
@@ -62,7 +64,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Cancellati
6264
includeProjectNonLocalResult, cancellationToken).ConfigureAwait(false);
6365
}
6466

65-
protected async Task<ImmutableArray<DiagnosticData>> ProduceProjectDiagnosticsAsync(
67+
private async Task<ImmutableArray<DiagnosticData>> ProduceProjectDiagnosticsAsync(
6668
Project project, IReadOnlyList<DocumentId> documentIds,
6769
bool includeProjectNonLocalResult, CancellationToken cancellationToken)
6870
{
@@ -72,30 +74,14 @@ await this.ProduceDiagnosticsAsync(
7274
return builder.ToImmutableAndClear();
7375
}
7476

75-
protected void AddIncludedDiagnostics(ArrayBuilder<DiagnosticData> builder, ImmutableArray<DiagnosticData> diagnostics)
77+
private void AddIncludedDiagnostics(ArrayBuilder<DiagnosticData> builder, ImmutableArray<DiagnosticData> diagnostics)
7678
{
7779
foreach (var diagnostic in diagnostics)
7880
{
7981
if (ShouldIncludeDiagnostic(diagnostic))
8082
builder.Add(diagnostic);
8183
}
8284
}
83-
}
84-
85-
private sealed class IdeLatestDiagnosticGetter(
86-
DiagnosticIncrementalAnalyzer owner,
87-
Solution solution,
88-
ProjectId projectId,
89-
DocumentId? documentId,
90-
ImmutableHashSet<string>? diagnosticIds,
91-
Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer,
92-
bool includeLocalDocumentDiagnostics,
93-
bool includeNonLocalDocumentDiagnostics)
94-
: DiagnosticGetter(
95-
owner, solution, projectId, documentId, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics)
96-
{
97-
private readonly ImmutableHashSet<string>? _diagnosticIds = diagnosticIds;
98-
private readonly Func<DiagnosticAnalyzer, bool>? _shouldIncludeAnalyzer = shouldIncludeAnalyzer;
9985

10086
public async Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsAsync(CancellationToken cancellationToken)
10187
{
@@ -107,10 +93,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsAsync(Can
10793
project, documentIds: [], includeProjectNonLocalResult: true, cancellationToken).ConfigureAwait(false);
10894
}
10995

110-
protected override bool ShouldIncludeDiagnostic(DiagnosticData diagnostic)
111-
=> _diagnosticIds == null || _diagnosticIds.Contains(diagnostic.Id);
112-
113-
protected override async Task ProduceDiagnosticsAsync(
96+
private async Task ProduceDiagnosticsAsync(
11497
Project project,
11598
IReadOnlyList<DocumentId> documentIds,
11699
bool includeProjectNonLocalResult,

0 commit comments

Comments
 (0)