Skip to content

Commit

Permalink
Merge pull request #68333 from mavasani/FixSuppressedDiagnosticsRegre…
Browse files Browse the repository at this point in the history
…ssion

Drop source suppressed diagnostics in LSP pull diagnostic handler
  • Loading branch information
mavasani authored May 26, 2023
2 parents 7c42798 + f0b2bc2 commit 3acd33d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(
// Also ensure we pass in "includeSuppressedDiagnostics = true" for unnecessary suppressions to be reported.
var allSpanDiagnostics = await diagnosticAnalyzerService.GetDiagnosticsForSpanAsync(
Document, range: null, diagnosticKind: this.DiagnosticKind, includeSuppressedDiagnostics: true, cancellationToken: cancellationToken).ConfigureAwait(false);

// Drop the source suppressed diagnostics.
// https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1824321 tracks
// adding LSP support for returning source suppressed diagnostics.
allSpanDiagnostics = allSpanDiagnostics.WhereAsArray(diagnostic => !diagnostic.IsSuppressed);

return allSpanDiagnostics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ void M()
}

[Theory, CombinatorialData, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1806590")]
public async Task TestDocumentDiagnosticsDiagnosticsForUnnecessarySuppressions(bool useVSDiagnostics, bool mutatingLspWorkspace)
public async Task TestDocumentDiagnosticsForUnnecessarySuppressions(bool useVSDiagnostics, bool mutatingLspWorkspace)
{
var markup = "#pragma warning disable IDE0000";
await using var testLspServer = await CreateTestWorkspaceWithDiagnosticsAsync(markup, mutatingLspWorkspace, BackgroundAnalysisScope.OpenFiles, useVSDiagnostics, pullDiagnostics: true);
Expand All @@ -804,6 +804,31 @@ public async Task TestDocumentDiagnosticsDiagnosticsForUnnecessarySuppressions(b
Assert.Equal(IDEDiagnosticIds.RemoveUnnecessarySuppressionDiagnosticId, results.Single().Diagnostics.Single().Code);
}

[Theory, CombinatorialData, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1824321")]
public async Task TestDocumentDiagnosticsForSourceSuppressions(bool useVSDiagnostics, bool mutatingLspWorkspace)
{
var markup = @"
class C
{
void M()
{
#pragma warning disable CS0168 // Variable is declared but never used
int x;
#pragma warning restore CS0168 // Variable is declared but never used
}
}";
await using var testLspServer = await CreateTestWorkspaceWithDiagnosticsAsync(markup, mutatingLspWorkspace, BackgroundAnalysisScope.OpenFiles, useVSDiagnostics, pullDiagnostics: true);

var document = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single();

await OpenDocumentAsync(testLspServer, document);

var results = await RunGetDocumentPullDiagnosticsAsync(
testLspServer, document.GetURI(), useVSDiagnostics);

Assert.Empty(results.Single().Diagnostics);
}

#endregion

#region Workspace Diagnostics
Expand Down

0 comments on commit 3acd33d

Please sign in to comment.