-
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
Allow semantic tokens in Razor to be better behaved #80815
Conversation
| refreshQueue.AllowRazorRefresh = true; | ||
| } | ||
|
|
||
| public static Task TryEnqueueRefreshComputationAsync(RazorCohostRequestContext requestContext, Project project, CancellationToken cancellationToken) |
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.
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)?
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.
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
| // 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. | |
| await semanticTokensRefreshQueue.TryEnqueueRefreshComputationAsync(project, cancellationToken).ConfigureAwait(false); |
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.
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.
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.
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.
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.
|
|
||
| // Changes to files with certain extensions (eg: razor) shouldn't trigger semantic a token refresh | ||
| if (DisallowsAdditionalDocumentChangedRefreshes(document.FilePath)) | ||
| if (!AllowRazorRefresh && DisallowsAdditionalDocumentChangedRefreshes(document.FilePath)) |
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
Fixes #11848 ~Consumes dotnet/roslyn#80815 to won't build until we bump Roslyn~ Update: This now needs to consume dotnet/roslyn#80830 because we already had an EA service for semantic tokens, so we should use it Just a bit of finishing touches to semantic tokens in cohosting.
* upstream/main: (123 commits) Fix SafeContext of Span-valued collection expressions to match specification (dotnet#80684) Improve detection of invalid references for implicitly typed expression variables declared within implicit object creation expressions. (dotnet#80546) Add test demonstrating behavior of ToMinimalDisplayString. (dotnet#80757) Only set DOTNET_HOST_PATH if something was installed (dotnet#80842) Clean up a Razor external access service (dotnet#80830) Remove unused statement (dotnet#80823) Allow foreach on typed null enumerables (dotnet#80783) Update documentation for DeclaringSyntaxReferences and Locations to clarify partial members behavior (dotnet#80704) Fix issue converting an auto prop to a full prop when 'field' and 'initializers' are involved Rename childIsSimple to innerExpressionHasPrimaryPrecedence and add more test cases Remove placeholder WorkItem attributes from new tests Fix RemoveUnnecessaryParentheses to detect simple expressions in bitwise operations [main] Update dependencies from dotnet/arcade (dotnet#80828) Fix ITypeSymbol.BaseType documentation for type parameters (dotnet#80770) soft-select select camelcase matched item if user might be typing an undefined type parameter (dotnet#80809) Allow semantic tokens in Razor to be better behaved (dotnet#80815) Rebase Remove using Update test Add fix all test ...
Part of dotnet/razor#11848
This makes the Razor experience for semantic tokens the same as the C# experience for the most part.
Razor side: dotnet/razor#12367