Skip to content

Conversation

@davidwengier
Copy link
Member

@davidwengier davidwengier commented Oct 19, 2025

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

refreshQueue.AllowRazorRefresh = true;
}

public static Task TryEnqueueRefreshComputationAsync(RazorCohostRequestContext requestContext, Project project, CancellationToken cancellationToken)
Copy link
Member

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)?

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 mirroring the Roslyn functionality its semantic tokens handler, where after every request it triggers a refresh:

// 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.

Copy link
Member

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.

Copy link
Member Author

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))
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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

@davidwengier davidwengier merged commit 17d42dc into dotnet:main Oct 20, 2025
26 checks passed
@davidwengier davidwengier deleted the RazorSemanticTokensInit branch October 20, 2025 21:58
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 20, 2025
davidwengier added a commit to davidwengier/roslyn that referenced this pull request Oct 21, 2025
davidwengier added a commit to dotnet/razor that referenced this pull request Oct 21, 2025
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.
333fred added a commit to 333fred/roslyn that referenced this pull request Oct 22, 2025
* 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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants