-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Allow semantic tokens in Razor to be better behaved #80815
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,25 +13,28 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers | |||||||||||
| { | ||||||||||||
| internal static class SemanticTokensRange | ||||||||||||
| { | ||||||||||||
| public static void RegisterRefresh(RazorCohostRequestContext requestContext) | ||||||||||||
| { | ||||||||||||
| var refreshQueue = requestContext.GetRequiredService<SemanticTokensRefreshQueue>(); | ||||||||||||
| refreshQueue.AllowRazorRefresh = true; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public static Task TryEnqueueRefreshComputationAsync(RazorCohostRequestContext requestContext, Project project, CancellationToken cancellationToken) | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so it looks like you're allowing Razor to manually call a refresh and opting in to the Roslyn automatic refreshing done as part of the queue. Can you elaborate on why both are required (i.e. why this can't only be done on the Razor side, or only be done on the Roslyn side)?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mirroring the Roslyn functionality its semantic tokens handler, where after every request it triggers a refresh: roslyn/src/LanguageServer/Protocol/Handler/SemanticTokens/SemanticTokensHelpers.cs Lines 48 to 52 in bb57f46
Razor calls in to the method just below that, so doesn't get that behaviour, but the Razor call happens in OOP so we can't call in to the higher level. Razor could just trigger a refresh itself, but the queue does debouncing and checksum checking, and it makes sense to me that everything just funnels into the one queue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. So this is something that doesn't work for Razor because the handler on our side runs in-proc. If it ran out of proc instead you could just rely on the request to compute semantic tokens to trigger the refresh as well.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Essentially, yes. Where you run the handler wouldn't matter, since the requests hit Razors handler, but if we called into something that knew it was OOP, and routed the Enqueue call back to in proc, then yes we could just call that. |
||||||||||||
| { | ||||||||||||
| var refreshQueue = requestContext.GetRequiredService<SemanticTokensRefreshQueue>(); | ||||||||||||
| return refreshQueue.TryEnqueueRefreshComputationAsync(project, cancellationToken); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public static Task<int[]> GetSemanticTokensAsync( | ||||||||||||
| Document document, | ||||||||||||
| ImmutableArray<LinePositionSpan> spans, | ||||||||||||
| bool supportsVisualStudioExtensions, | ||||||||||||
| CancellationToken cancellationToken) | ||||||||||||
| { | ||||||||||||
| var tokens = SemanticTokensHelpers.HandleRequestHelperAsync( | ||||||||||||
| => SemanticTokensHelpers.HandleRequestHelperAsync( | ||||||||||||
| document, | ||||||||||||
| spans, | ||||||||||||
| supportsVisualStudioExtensions, | ||||||||||||
| ClassificationOptions.Default, | ||||||||||||
| cancellationToken); | ||||||||||||
|
|
||||||||||||
| // The above call to get semantic tokens may be inaccurate (because we use frozen partial semantics). Kick | ||||||||||||
| // off a request to ensure that the OOP side gets a fully up to compilation for this project. Once it does | ||||||||||||
| // we can optionally choose to notify our caller to do a refresh if we computed a compilation for a new | ||||||||||||
| // solution snapshot. | ||||||||||||
| // TODO: await semanticTokensRefreshQueue.TryEnqueueRefreshComputationAsync(project, cancellationToken).ConfigureAwait(false); | ||||||||||||
| return tokens; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a separate boolean here, and can't just remove the disallows check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cohosting is still only optional, so I'm just being cautious until the old LSP editor is removed. With cohosting off it would mean Roslyn is asking for a refresh for a document that isn't doesn't handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it - so this is a part that can be deleted when cohosting is the only mechanism
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can be part of the great code purge. Hopefully sometime in 2026? :D