Skip to content

Conversation

@davidwengier
Copy link
Member

@davidwengier davidwengier commented Jul 25, 2025

Fixes #12054
Part of #9519
Needs dotnet/roslyn#79604 and dotnet/roslyn#79677 to insert before this will build

This PR implements the workspace version of our span mapping service, since the old one is hooked up via a document service, which we can't do in cohosting.

@davidwengier davidwengier requested a review from a team as a code owner July 25, 2025 12:20
davidwengier added a commit to dotnet/roslyn that referenced this pull request Jul 28, 2025
…ts (#79604)

Part of dotnet/razor#9519
Half of the fix for dotnet/razor#12054, along
with the Razor side at dotnet/razor#12055

Previously I allowed rename to work on any source generated document,
but made it only opt in for when the rename request came from Razor. Now
that we have a little more time for development, it's time to finish the
feature off properly. This PR:

* Rename will only consider source generated documents if they're from
Razor
* Any rename operation will automatically do so, without opt in
* Before applying changes to the workspace, we call in to Razor to map
edits
* This matches the behaviour of non-cohosting, but that does edit
mapping via a document service. Since with cohosting Razor doesn't
control the document creation, there is no way to set up a document
service, so there is just a workspace service that does the same thing.

There will still need to be more PRs to make this work in VS Code, and
to hook up the span mapping aspect of the service, but I didn't want
this PR to get too big.
@davidwengier davidwengier requested a review from a team as a code owner July 29, 2025 21:53
@davidwengier
Copy link
Member Author

Gonna wait for dotnet/roslyn#79677 and do this and span mapping at the same time, because I tweaked the API in the EA layer.

{
public static bool IsRazorSourceGeneratedDocument(this RazorGeneratedDocumentIdentity identity)
{
return identity.GeneratorTypeName == typeof(RazorSourceGenerator).FullName;
Copy link
Member

Choose a reason for hiding this comment

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

When would we ever have a RazorGeneratedDocumentIdentity that wasn't from our source generator?

Copy link
Member Author

Choose a reason for hiding this comment

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

When I wrote this, yeah, we could get them when, for example, you renamed a method from a Razor file, where the method was defined in C# and generated by the System.Text.Json or Regex generators. I've made recent changes in Roslyn to rename that prevents that now, but it wouldn't take much change on the Roslyn side for that to be undone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename from a C# document doesn't change anything in a Razor document Various IDE scenarios will stop working without document services

3 participants