From 66139efa51cdc6918c90066f6366b77cac5d7361 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 7 Feb 2025 10:27:18 -0800 Subject: [PATCH] Merge base and parent type in diagnostic subsystem --- ...osticIncrementalAnalyzer_GetDiagnostics.cs | 55 +++++++------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs index 3d1532fd0183e..efd20ab728d24 100644 --- a/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs +++ b/src/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs @@ -18,33 +18,35 @@ internal partial class DiagnosticAnalyzerService private partial class DiagnosticIncrementalAnalyzer { public Task> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet? diagnosticIds, Func? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) - => new IdeLatestDiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken); + => new DiagnosticGetter(this, solution, projectId, documentId, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics).GetDiagnosticsAsync(cancellationToken); public Task> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, ImmutableHashSet? diagnosticIds, Func? shouldIncludeAnalyzer, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken) - => new IdeLatestDiagnosticGetter(this, solution, projectId, documentId: null, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics: false, includeNonLocalDocumentDiagnostics).GetProjectDiagnosticsAsync(cancellationToken); + => new DiagnosticGetter(this, solution, projectId, documentId: null, diagnosticIds, shouldIncludeAnalyzer, includeLocalDocumentDiagnostics: false, includeNonLocalDocumentDiagnostics).GetProjectDiagnosticsAsync(cancellationToken); - private abstract class DiagnosticGetter( + private sealed class DiagnosticGetter( DiagnosticIncrementalAnalyzer owner, Solution solution, ProjectId projectId, DocumentId? documentId, + ImmutableHashSet? diagnosticIds, + Func? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics) { - protected readonly DiagnosticIncrementalAnalyzer Owner = owner; - - protected readonly Solution Solution = solution; - protected readonly ProjectId ProjectId = projectId; - protected readonly DocumentId? DocumentId = documentId; - protected readonly bool IncludeLocalDocumentDiagnostics = includeLocalDocumentDiagnostics; - protected readonly bool IncludeNonLocalDocumentDiagnostics = includeNonLocalDocumentDiagnostics; + private readonly DiagnosticIncrementalAnalyzer Owner = owner; - protected StateManager StateManager => Owner._stateManager; + private readonly Solution Solution = solution; + private readonly ProjectId ProjectId = projectId; + private readonly DocumentId? DocumentId = documentId; + private readonly ImmutableHashSet? _diagnosticIds = diagnosticIds; + private readonly Func? _shouldIncludeAnalyzer = shouldIncludeAnalyzer; + private readonly bool IncludeLocalDocumentDiagnostics = includeLocalDocumentDiagnostics; + private readonly bool IncludeNonLocalDocumentDiagnostics = includeNonLocalDocumentDiagnostics; - protected virtual bool ShouldIncludeDiagnostic(DiagnosticData diagnostic) => true; + private StateManager StateManager => Owner._stateManager; - protected abstract Task ProduceDiagnosticsAsync( - Project project, IReadOnlyList documentIds, bool includeProjectNonLocalResult, ArrayBuilder builder, CancellationToken cancellationToken); + private bool ShouldIncludeDiagnostic(DiagnosticData diagnostic) + => _diagnosticIds == null || _diagnosticIds.Contains(diagnostic.Id); public async Task> GetDiagnosticsAsync(CancellationToken cancellationToken) { @@ -62,7 +64,7 @@ public async Task> GetDiagnosticsAsync(Cancellati includeProjectNonLocalResult, cancellationToken).ConfigureAwait(false); } - protected async Task> ProduceProjectDiagnosticsAsync( + private async Task> ProduceProjectDiagnosticsAsync( Project project, IReadOnlyList documentIds, bool includeProjectNonLocalResult, CancellationToken cancellationToken) { @@ -72,7 +74,7 @@ await this.ProduceDiagnosticsAsync( return builder.ToImmutableAndClear(); } - protected void AddIncludedDiagnostics(ArrayBuilder builder, ImmutableArray diagnostics) + private void AddIncludedDiagnostics(ArrayBuilder builder, ImmutableArray diagnostics) { foreach (var diagnostic in diagnostics) { @@ -80,22 +82,6 @@ protected void AddIncludedDiagnostics(ArrayBuilder builder, Immu builder.Add(diagnostic); } } - } - - private sealed class IdeLatestDiagnosticGetter( - DiagnosticIncrementalAnalyzer owner, - Solution solution, - ProjectId projectId, - DocumentId? documentId, - ImmutableHashSet? diagnosticIds, - Func? shouldIncludeAnalyzer, - bool includeLocalDocumentDiagnostics, - bool includeNonLocalDocumentDiagnostics) - : DiagnosticGetter( - owner, solution, projectId, documentId, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics) - { - private readonly ImmutableHashSet? _diagnosticIds = diagnosticIds; - private readonly Func? _shouldIncludeAnalyzer = shouldIncludeAnalyzer; public async Task> GetProjectDiagnosticsAsync(CancellationToken cancellationToken) { @@ -107,10 +93,7 @@ public async Task> GetProjectDiagnosticsAsync(Can project, documentIds: [], includeProjectNonLocalResult: true, cancellationToken).ConfigureAwait(false); } - protected override bool ShouldIncludeDiagnostic(DiagnosticData diagnostic) - => _diagnosticIds == null || _diagnosticIds.Contains(diagnostic.Id); - - protected override async Task ProduceDiagnosticsAsync( + private async Task ProduceDiagnosticsAsync( Project project, IReadOnlyList documentIds, bool includeProjectNonLocalResult,