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

Push diagnostic suppression filtering flag to feature levels #76849

Merged
merged 12 commits into from
Jan 22, 2025

Conversation

CyrusNajmabadi
Copy link
Member

This flag was pushed all the way down to the compiler layer. But all the compiler uses it for is for filtering out diagnostics with the .IsSuppressed bit on it. This is a lot of scaffolding through lots of complex layers (including caching layers) only to just filter the diagnostics. There are not that many features that actually consume diagnostics, so we it's fine to just compute all the diagnostics like normal and have the filtering be at the feature level.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 22, 2025
@@ -128,7 +128,6 @@ private async Task ProduceTagsAsync(
document,
requestedSpan.Span.ToTextSpan(),
diagnosticKind: _diagnosticKind,
includeSuppressedDiagnostics: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if a featuree passes includeSuppressedDiagnostics: true, it needs no change. We always return all diagnostics by default, including suppressed ones.

@@ -69,7 +69,8 @@ public async Task TestHasSuccessfullyLoadedBeingFalse()

var diagnostics = await analyzer.GetDiagnosticsForIdsAsync(
workspace.CurrentSolution, projectId: null, documentId: null, diagnosticIds: null, shouldIncludeAnalyzer: null, getDocuments: null,
includeSuppressedDiagnostics: false, includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: false, CancellationToken.None);
includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: false, CancellationToken.None);
diagnostics = diagnostics.WhereAsArray(d => !d.IsSuppressed);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: code that passes includeSuppressedDiagnostics: false needs to filter the results. I do that for features. HOwever, for tests, it doesn't seem to have any impact on results. so for simplicity i'm not doing it.

@@ -69,7 +69,8 @@ public async Task TestHasSuccessfullyLoadedBeingFalse()

var diagnostics = await analyzer.GetDiagnosticsForIdsAsync(
workspace.CurrentSolution, projectId: null, documentId: null, diagnosticIds: null, shouldIncludeAnalyzer: null, getDocuments: null,
includeSuppressedDiagnostics: false, includeLocalDocumentDiagnostics: true, includeNonLocalDocumentDiagnostics: false, CancellationToken.None);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: code that passes includeSuppressedDiagnostics: false needs to filter the results. I do that for features. HOwever, for tests, it doesn't seem to have any impact on results. so for simplicity i'm not doing it.

var diagnostics = await _diagnosticAnalyzerService.GetCachedDiagnosticsAsync(
_workspace, documentId.ProjectId, documentId, includeLocalDocumentDiagnostics: true,
includeNonLocalDocumentDiagnostics: true, cancellationToken).ConfigureAwait(false);
return diagnostics.WhereAsArray(d => !d.IsSuppressed);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any place that previously passed includeSuppressedDiagnostics: false into the service, now just filters the result.

Note: i wouldn't mind having this not be here, and pushignt his even higher all the way to the feature layer. but this is a simple starting step.

/// Flag indicating if suppressed diagnostics should be returned.
/// </summary>
[DataMember(Order = 0)]
public bool ReportSuppressedDiagnostics;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed. they are always returned.

TextDocument document, TextSpan? range, DiagnosticKind diagnosticKind, CancellationToken cancellationToken)
=> service.GetDiagnosticsForSpanAsync(
document, range,
diagnosticId: null,
priorityProvider: new DefaultCodeActionRequestPriorityProvider(),
diagnosticKind, isExplicit: false, cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any code that just passed the flag along just has it removed.

callback(diagnostic);
}
}

private bool ShouldIncludeSuppressedDiagnostic(DiagnosticData diagnostic)
=> IncludeSuppressedDiagnostics || !diagnostic.IsSuppressed;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what the flag was passed down all the way to do.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review January 22, 2025 17:24
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 22, 2025 17:24
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal.

@@ -50,7 +50,8 @@ private async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(
var text = await document.GetTextAsync().ConfigureAwait(false);
var dxs = await _diagnosticAnalyzerService.GetDiagnosticsForIdsAsync(
project.Solution, project.Id, document.Id, diagnosticIds: null, shouldIncludeAnalyzer: null,
_includeSuppressedDiagnostics, includeLocalDocumentDiagnostics: true, _includeNonLocalDocumentDiagnostics, CancellationToken.None);
includeLocalDocumentDiagnostics: true, _includeNonLocalDocumentDiagnostics, CancellationToken.None);
dxs = dxs.WhereAsArray(d => _includeSuppressedDiagnostics || !d.IsSuppressed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_includeSuppressedDiagnostics

another place where I think it would read easier to me to have the _includeSuppressedDiagnostics checked in an external if.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enh. this is tests. i'm fine with this.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants