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

Reenable LSP pull diagnostics #48328

Merged
merged 41 commits into from
Oct 20, 2020

Conversation

CyrusNajmabadi
Copy link
Member

This reverts commit 02a9e20.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner October 5, 2020 15:13
@dibarbet dibarbet changed the base branch from master-vs-deps to master October 7, 2020 19:05
@dibarbet
Copy link
Member

dibarbet commented Oct 8, 2020

@CyrusNajmabadi when you have time, this will need latest master merged in to fix the failures (or let me know and I can update your branch)

edit - nvm it isn't merged in yet - spoke too soon!

@CyrusNajmabadi CyrusNajmabadi changed the title Revert "Revert "Merge pull request #47914 from CyrusNajmabadi/lspDiagnostics"" Reenable LSP pull diagnostics Oct 15, 2020
@@ -151,7 +151,7 @@ private void ProduceTags(TaggerContext<TTag> context, DocumentSnapshotSpan spanT
buffer?.Properties.TryGetProperty(PredefinedPreviewTaggerKeys.SuppressDiagnosticsSpansKey, out suppressedDiagnosticsSpans);

var buckets = _diagnosticService.GetDiagnosticBuckets(
workspace, document.Project.Id, document.Id, context.CancellationToken);
workspace, document.Project.Id, document.Id, forPullDiagnostics: false, context.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.

an intermediary concept this PR introduces is that the two major clients of the diagnostics subsystem now pass in what behavior they want when calling into the DiagnosticService singleton.

i.e. the normal push features call in saying forPullDiagnostics: false and the lsp system calls in saying forPullDiagnostics: true. Internally we see which mode we're actually in and we either pass along the diagnostics, or pass along empty. in essence only one side will work, and the other will see absolutely no diagnostics ever.

This is not pretty, but it was:

  1. the cleanest way i could find to keep both systems around
  2. required minimal and mechanical changes to both systems.
  3. ensured that every entrypoint was guarded so diagnostics wouldn't accidentally sneak into the wrong client.

Once we are entirely on pull, all the push components can go away (as can tehse booleans).

// If this is a pull client, but pull diagnostics is not on, then they get nothing. Similarly, if this is a
// push client and pull diagnostics are on, they get nothing.
if (forPullDiagnostics != workspace.Options.GetOption(InternalDiagnosticsOptions.LspPullDiagnostics))
return ImmutableArray<DiagnosticData>.Empty;
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 one of 3 main entrypoints that now ensures the right data flows out depending on the caller's needs. If the caller doesn't match the current diagnostics-mode we're in (either 'push' or 'pull') they get nothing back. This allows DiagnosticService to still be the centralized authority that everyone uses.

// If this is a pull client, but pull diagnostics is not on, then they get nothing. Similarly, if this is a
// push client and pull diagnostics are on, they get nothing.
if (forPullDiagnostics != workspace.Options.GetOption(InternalDiagnosticsOptions.LspPullDiagnostics))
return ImmutableArray<DiagnosticBucket>.Empty;
Copy link
Member Author

Choose a reason for hiding this comment

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

second (of three) entrypoint that is updated.

// If this is a pull client, but pull diagnostics is not on, then they get nothing. Similarly, if this is a
// push client and pull diagnostics are on, they get nothing.
if (forPullDiagnostics != workspace.Options.GetOption(InternalDiagnosticsOptions.LspPullDiagnostics))
return ImmutableArray<DiagnosticData>.Empty;
Copy link
Member Author

Choose a reason for hiding this comment

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

third (of three) entrypoint that was updated.

@@ -20,7 +20,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService
internal abstract class AbstractLanguageServerClient : ILanguageClient
{
private readonly string? _diagnosticsClientName;
private readonly IDiagnosticService _diagnosticService;
Copy link
Member Author

Choose a reason for hiding this comment

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

all the lsp push diagnostic code is removed with this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The client is now sending a capability that tells us whether they support pull diagnostics (https://devdiv.visualstudio.com/DevDiv/_git/VSLanguageServerClient/pullrequest/279454?_a=files) so if that is false, we should keep this code running.

}

return ImmutableArray<LSP.Diagnostic>.Empty;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

yaay deleted code.

Copy link
Member

Choose a reason for hiding this comment

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

Super happy to delete this code - but this means that in order for razor to get diagnostics, they will have to set the feature flag to LSP diagnostics for regular c# files as well right? I'm OK with that but wanted to make sure that is the goal

@@ -159,7 +159,10 @@ private object CreateAggregationKey(DiagnosticsUpdatedArgs data)

private void PopulateInitialData(Workspace workspace, IDiagnosticService diagnosticService)
{
foreach (var bucket in diagnosticService.GetDiagnosticBuckets(workspace, projectId: null, documentId: null, cancellationToken: CancellationToken.None))
var diagnostics = diagnosticService.GetDiagnosticBuckets(
workspace, projectId: null, documentId: null, forPullDiagnostics: false, cancellationToken: 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.

All existing code calls forPullDiagnostics: false.

var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
using var _ = ArrayBuilder<VSDiagnostic>.GetInstance(out var result);

var diagnostics = _diagnosticService.GetDiagnostics(document, includeSuppressedDiagnostics: false, forPullDiagnostics: true, 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.

this is new code. it calls forPullDiagnostics: true as it wants to only run if we're explicitly opted-into pull mode.

Copy link
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.

a few comments, but nothing blocking!

SupportsDiagnosticRequests = true,
};
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Yep this looks good!
Do we want to conditionally set this capability based on the feature flag? That way we can avoid having the client even call into us if it's off. Might be too minor of an optimization though.

}

return ImmutableArray<LSP.Diagnostic>.Empty;
}
Copy link
Member

Choose a reason for hiding this comment

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

Super happy to delete this code - but this means that in order for razor to get diagnostics, they will have to set the feature flag to LSP diagnostics for regular c# files as well right? I'm OK with that but wanted to make sure that is the goal

@CyrusNajmabadi
Copy link
Member Author

Do we want to conditionally set this capability based on the feature flag?

Yes. That seems reasonable :)

@CyrusNajmabadi
Copy link
Member Author

Super happy to delete this code - but this means that in order for razor to get diagnostics, they will have to set the feature flag to LSP diagnostics for regular c# files as well right? I'm OK with that but wanted to make sure that is the goal

Yeah, i'm ok with that :)

@CyrusNajmabadi CyrusNajmabadi merged commit 242160f into dotnet:master Oct 20, 2020
@ghost ghost added this to the Next milestone Oct 20, 2020
@CyrusNajmabadi CyrusNajmabadi deleted the lspDiagnostics2 branch October 20, 2020 01:56
@allisonchou allisonchou modified the milestones: Next, 16.9.P2 Nov 24, 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.

6 participants