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

Fix issues with pull diagnostics in VSCode #73248

Merged
merged 6 commits into from
Apr 27, 2024

Conversation

dibarbet
Copy link
Member

VSCode integration tests caught an issue with the mef based pull diagnostics support in the insertion - dotnet/vscode-csharp#7069

Essentially diagnostics were getting duplicated due to the registration of source names and the static registration (of no source name).

This fixes the issue and also cleans up a few bits and pieces around the source handling in vscode.

@dibarbet dibarbet requested a review from a team as a code owner April 26, 2024 21:46
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 26, 2024
@dibarbet dibarbet changed the title Fix pull diags Fix issues with pull diagnostics in VSCode Apr 26, 2024
@@ -120,16 +120,6 @@ public ServerCapabilities GetCapabilities(ClientCapabilities clientCapabilities)
// Using VS server capabilities because we have our own custom client.
capabilities.OnAutoInsertProvider = new VSInternalDocumentOnAutoInsertOptions { TriggerCharacters = ["'", "/", "\n"] };

if (!supportsVsExtensions)
{
capabilities.DiagnosticOptions = new DiagnosticOptions
Copy link
Member Author

@dibarbet dibarbet Apr 26, 2024

Choose a reason for hiding this comment

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

this was the root cause of duplicate diagnostics in vscode - we were registering for requests with no identifier and also for requests with an identifier later on in dynamic registration

@@ -45,11 +45,11 @@ public DiagnosticSourceManager([ImportMany] IEnumerable<IDiagnosticSourceProvide
.ToImmutableDictionary(kvp => kvp.Name, kvp => kvp);
}

public ImmutableArray<string> GetDocumentSourceProviderNames()
=> _nameToDocumentProviderMap.Keys.ToImmutableArray();
public ImmutableArray<string> GetDocumentSourceProviderNames(ClientCapabilities clientCapabilities)
Copy link
Member Author

Choose a reason for hiding this comment

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

Allows us to filter the diagnostic sources based on the client (e.g. no task diagnostics in vscode).

// that also sets the workspace pull option.
//
// So we build up a unique set of source names and mark if each one is also a workspace source.
var allSources = documentSources
Copy link
Member Author

@dibarbet dibarbet Apr 26, 2024

Choose a reason for hiding this comment

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

previously the doc handler registered doc sources and the workspace handler registered workspace sources. However this meant that sources using the same identifer for doc and workspace would overwrite each other - because vscode requires us to register all identifiers as document sources (even if they are workspace only).

now we register them all once (and set the workspace option appropriately if it also participates in workspace requests).

@@ -114,14 +114,15 @@ private protected override TestAnalyzerReferenceByLanguage CreateTestAnalyzersRe
TestLspServer testLspServer,
ImmutableArray<(string resultId, TextDocumentIdentifier identifier)>? previousResults,
bool useProgress,
string? category,
Copy link
Member Author

Choose a reason for hiding this comment

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

fix tests to pass category in public requests.


return results.Select(r => (r.ResultId, r.TextDocument)).ToImmutableArray();
// If there was no resultId provided in the response, we cannot create previous results for it.
return results.Where(r => r.ResultId != null).Select(r => (r.ResultId!, r.TextDocument)).ToImmutableArray();
Copy link
Member Author

Choose a reason for hiding this comment

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

fixes a bug in the tests discovered when enabling categories for public workspace diagnoistics - we incorrectly sent back a non-null PreviousResultId object with a null resultId (not allowed)

@@ -73,14 +73,14 @@ public async Task TestDocumentDiagnosticsForOpenFilesWithFSAOff(bool useVSDiagno
}

[Theory, CombinatorialData, WorkItem("https://github.com/dotnet/fsharp/issues/15972")]
public async Task TestDocumentDiagnosticsForOpenFilesWithFSAOff_Categories(bool mutatingLspWorkspace)
public async Task TestDocumentDiagnosticsForOpenFilesWithFSAOff_Categories(bool useVSDiagnostics, bool mutatingLspWorkspace)
Copy link
Member Author

Choose a reason for hiding this comment

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

Modified the tests to test categories in the public version as well.

@@ -181,37 +181,14 @@ static void Main(string[] args)
}

[Theory, CombinatorialData]
public async Task TestDocumentTodoCommentsDiagnosticsForOpenFile_NoCategory(bool useVSDiagnostics, bool mutatingLspWorkspace)
public async Task TestDocumentTodoCommentsDiagnosticsForOpenFile_Category(bool mutatingLspWorkspace)
Copy link
Member Author

Choose a reason for hiding this comment

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

modified the tests to correctly only test todo comments in the VS version.

…nosticRegistrationTests.cs

Co-authored-by: Cyrus Najmabadi <[email protected]>
@dibarbet dibarbet merged commit 8f9fad1 into dotnet:main Apr 27, 2024
25 checks passed
@dibarbet dibarbet deleted the fix_pull_diags branch April 27, 2024 00:06
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 27, 2024
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants