Skip to content

Fix for LSP diagnostic bugs#41619

Merged
allisonchou merged 7 commits intodotnet:masterfrom
allisonchou:NexusDiagnosticBug
Feb 15, 2020
Merged

Fix for LSP diagnostic bugs#41619
allisonchou merged 7 commits intodotnet:masterfrom
allisonchou:NexusDiagnosticBug

Conversation

@allisonchou
Copy link
Copy Markdown
Contributor

Fixes bug where IDE info diagnostics are reported as warnings with purple squiggles (https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1062989).

Also partially fixes #41029, pending a bug fix from LSP side (https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1067885).

@allisonchou allisonchou requested review from a team and dibarbet February 12, 2020 20:34
Copy link
Copy Markdown
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

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

Mostly looks good, just a couple async concerns

DocumentRangeFormattingProvider = true,
DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingOptions { FirstTriggerCharacter = "}", MoreTriggerCharacter = new[] { ";", "\n" } },
DocumentHighlightProvider = true,
TextDocumentSync = new TextDocumentSyncOptions { OpenClose = true }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this since the notifications aren't propagated through live share yet?


#pragma warning disable VSTHRD100 // Avoid async void methods
private async void DiagnosticService_DiagnosticsUpdated(object sender, DiagnosticsUpdatedArgs e)
private async void PublishDiagnosticsAsync(Solution solution, Document document)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should just return Task, then you can remove the suppression.

var document = _workspace.CurrentSolution.GetDocument(documentId);
if (document != null)
{
PublishDiagnosticsAsync(_workspace.CurrentSolution, document);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PublishDiagnosticsAsync should return a task, then can return the result of PublishDiagnosticsAsync here. Right now it will trigger PublishDiagnosticsAsync and will return a CompletedTask before PublishDiagnosticsAsync completes.

return await _protocol.GetWorkspaceSymbolsAsync(_workspace.CurrentSolution, workspaceSymbolParams, _clientCapabilities, cancellationToken).ConfigureAwait(false);
}

private void DiagnosticService_DiagnosticsUpdated(object sender, DiagnosticsUpdatedArgs e)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is still the one triggered by the event handler, this should still be async void and wrapped in the try catch instead of in PublishDiagnosticsAsync.

{
// Since this is an async void method, exceptions here will crash the host VS. We catch exceptions here to make sure that we don't crash the host since
// the worst outcome here is that guests may not see all diagnostics.
try
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This try catch should be in the event handler method.

DocumentRangeFormattingProvider = true,
DocumentOnTypeFormattingProvider = new DocumentOnTypeFormattingOptions { FirstTriggerCharacter = "}", MoreTriggerCharacter = new[] { ";", "\n" } },
DocumentHighlightProvider = true,
DocumentHighlightProvider = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
DocumentHighlightProvider = true
DocumentHighlightProvider = true,

var document = _workspace.CurrentSolution.GetDocument(documentId);
if (document != null)
{
await PublishDiagnosticsAsync(_workspace.CurrentSolution, document).ConfigureAwait(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

continually referencing _workspace.CurrentSolution is very scary. it could change over time. Instead, pull this out above hte foreach look and always reference the same instance. Passing that instance into PublishDiagnosticsAsync shouldn't be necessary either. it's redundant given that document is passed in.

@allisonchou allisonchou merged commit 8643742 into dotnet:master Feb 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LSP] Diagnostic squiggles don't appear for client until edits are made

4 participants