Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge base and parent type in diagnostic subsystem #77110

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,35 @@ internal partial class DiagnosticAnalyzerService
private partial class DiagnosticIncrementalAnalyzer
{
public Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? 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<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(Solution solution, ProjectId projectId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? 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<string>? diagnosticIds,
Func<DiagnosticAnalyzer, bool>? 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<string>? _diagnosticIds = diagnosticIds;
private readonly Func<DiagnosticAnalyzer, bool>? _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<DocumentId> documentIds, bool includeProjectNonLocalResult, ArrayBuilder<DiagnosticData> builder, CancellationToken cancellationToken);
private bool ShouldIncludeDiagnostic(DiagnosticData diagnostic)
=> _diagnosticIds == null || _diagnosticIds.Contains(diagnostic.Id);

public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(CancellationToken cancellationToken)
{
Expand All @@ -62,7 +64,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Cancellati
includeProjectNonLocalResult, cancellationToken).ConfigureAwait(false);
}

protected async Task<ImmutableArray<DiagnosticData>> ProduceProjectDiagnosticsAsync(
private async Task<ImmutableArray<DiagnosticData>> ProduceProjectDiagnosticsAsync(
Project project, IReadOnlyList<DocumentId> documentIds,
bool includeProjectNonLocalResult, CancellationToken cancellationToken)
{
Expand All @@ -72,30 +74,14 @@ await this.ProduceDiagnosticsAsync(
return builder.ToImmutableAndClear();
}

protected void AddIncludedDiagnostics(ArrayBuilder<DiagnosticData> builder, ImmutableArray<DiagnosticData> diagnostics)
private void AddIncludedDiagnostics(ArrayBuilder<DiagnosticData> builder, ImmutableArray<DiagnosticData> diagnostics)
{
foreach (var diagnostic in diagnostics)
{
if (ShouldIncludeDiagnostic(diagnostic))
builder.Add(diagnostic);
}
}
}

private sealed class IdeLatestDiagnosticGetter(
DiagnosticIncrementalAnalyzer owner,
Solution solution,
ProjectId projectId,
DocumentId? documentId,
ImmutableHashSet<string>? diagnosticIds,
Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer,
bool includeLocalDocumentDiagnostics,
bool includeNonLocalDocumentDiagnostics)
: DiagnosticGetter(
owner, solution, projectId, documentId, includeLocalDocumentDiagnostics, includeNonLocalDocumentDiagnostics)
{
private readonly ImmutableHashSet<string>? _diagnosticIds = diagnosticIds;
private readonly Func<DiagnosticAnalyzer, bool>? _shouldIncludeAnalyzer = shouldIncludeAnalyzer;

public async Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsAsync(CancellationToken cancellationToken)
{
Expand All @@ -107,10 +93,7 @@ public async Task<ImmutableArray<DiagnosticData>> 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<DocumentId> documentIds,
bool includeProjectNonLocalResult,
Expand Down
Loading