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

Query workspace for active document when we are not passed a project context in an LSP request #54397

Merged
merged 2 commits into from
Jun 28, 2021

Conversation

dibarbet
Copy link
Member

@dibarbet dibarbet commented Jun 25, 2021

In only-LSP scenarios, LSP determines the project context when the LSP navbar is active. LSP is able to handle dropdownbar events, query the server for all project contexts, and then handle selection events when the user switches the context.

However, we are not able to enable the LSP NavBar in classic scenarios due to missing features (code generation, multiple ranges, missing icons, etc). So for LSP pull diagnostics in classic, the LSP client does not know which project context is active as Roslyn is handling all NavBar integration (outside of LSP). Per conversations with the editor, the lsp client is not easily able to query for the active dropdown and convert that result into the project context needed to pass with LSP pull diagnostics requests.

The result of this issue is that LSP pull diagnostics currently does not return errors for the correct context. It arbitrarily picks the first project context ( can result in incorrect squiggles). To temporarily solve this issue, we can query the workspace for the document in the current context.

I am also in favor of blocking enabling additional LSP features in classic scenarios on full LSP navbar support. This should only be used for the diagnostics experiment.

passed a project context in an LSP request.

// Lookup the active document and determine if any of the documents from the request URI match.
var solution = documents.First().Project.Solution;
var service = solution.Workspace.Services.GetRequiredService<IDocumentTrackingService>();
Copy link
Member

Choose a reason for hiding this comment

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

instead of IDocumentTrackingService just use:

internal DocumentId GetDocumentIdInCurrentContext(DocumentId documentId)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahhh of course! Will switch to that

@dibarbet dibarbet changed the title Query IDocumentTrackingService for active document when we are not passed a project context in an LSP request Query workspace for active document when we are not passed a project context in an LSP request Jun 26, 2021
@dibarbet dibarbet marked this pull request as ready for review June 26, 2021 00:40
@dibarbet dibarbet requested a review from a team as a code owner June 26, 2021 00:40

var solution = documents.First().Project.Solution;
// Lookup which of the linked documents is currently active in the workspace.
var documentIdInCurrentContext = solution.Workspace.GetDocumentIdInCurrentContext(documents.First().Id);
Copy link
Member

Choose a reason for hiding this comment

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

did this work?

else
{
// We were not passed a project context. This can happen when the LSP powered NavBar is not enabled.
// This branch should be removed when we're using the LSP based navbar in all scenarios.
Copy link
Member

Choose a reason for hiding this comment

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

can we have a tacking bug for that and link to that here?

Copy link
Member Author

@dibarbet dibarbet Jun 28, 2021

Choose a reason for hiding this comment

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

I'll link the tracking bug in code in a followup so I don't have to re-run CI on this - #54450

@dibarbet dibarbet merged commit b24e9ad into dotnet:main Jun 28, 2021
@ghost ghost added this to the Next milestone Jun 28, 2021
@dibarbet dibarbet deleted the active_context_16 branch June 28, 2021 19:52
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
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.

4 participants