Allow semantic tokens in Razor to be better behaved#80815
Allow semantic tokens in Razor to be better behaved#80815davidwengier merged 1 commit intodotnet:mainfrom
Conversation
| refreshQueue.AllowRazorRefresh = true; | ||
| } | ||
|
|
||
| public static Task TryEnqueueRefreshComputationAsync(RazorCohostRequestContext requestContext, Project project, CancellationToken cancellationToken) |
There was a problem hiding this comment.
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.
This is mirroring the Roslyn functionality its semantic tokens handler, where after every request it triggers a refresh:
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.
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.
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.
Why do we need a separate boolean here, and can't just remove the disallows check?
There was a problem hiding this comment.
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.
Got it - so this is a part that can be deleted when cohosting is the only mechanism
There was a problem hiding this comment.
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