Skip to content

Conversation

@davidwengier
Copy link
Member

Fixes #9829
Part of #8541

When renaming a component in a Razor file we now call Roslyn so that the component name or namespace is renamed in all C# code in the solution. With these changes, once dotnet/roslyn#81450 merges, we'll do the same when renaming a component type name from a C# file, including updating start and end component tags.

@davidwengier davidwengier requested a review from a team as a code owner November 26, 2025 01:36
@davidwengier davidwengier changed the title Failing tests Update C# code when Razor components are renamed Nov 26, 2025
@davidwengier davidwengier force-pushed the RenameCSharpWhenRenamingComponents branch from a9fae9c to cec69d7 Compare November 26, 2025 02:28
Comment on lines 383 to 385
// So that tooling can't observe or influence intermediate state, we don't give them the direct RazorCodeDocument
// that is our working state. Ideally it shouldn't be mutable at all of course
var outputDocument = codeDocument.ToHostOutput();
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, and the methods, will be superseded by #12533

…amingComponents

# Conflicts:
#	src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/AbstractEditMappingService.cs
#	src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/LspExtensions_WorkspaceEdit.cs
#	src/Razor/src/Microsoft.CodeAnalysis.Remote.Razor/Rename/RemoteRenameService.cs
@davidwengier
Copy link
Member Author

davidwengier commented Dec 2, 2025

Apologies for the noise in the last few commits, managed to cause myself conflicts and test breaks with other PRs I had. I think it should all be good now :)

if (node is BaseMarkupStartTagSyntax startTagSyntax &&
startTagSyntax.GetEndTag() is { } endTag)
{
// We are changing a start tag, and so we have a matching end tag. We have to translate the edit over there too
Copy link
Member

Choose a reason for hiding this comment

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

Would this be any easier if we mapped the end tags, or does it not make a difference?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we mapped end tags, then this little bit of code would be unnecessary, yeah.

BUT we'd either need new code-gen to map too, and it would be "fake" (ie, not relevant at runtime) or we'd have to map the same span twice. Writing this code was easier than doing that and seeing what broke, and sometimes I feel bad if we just map everything to C# and let Roslyn do all the hard work. There is a balance somewhere.

Copy link
Member

Choose a reason for hiding this comment

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

sometimes I feel bad if we just map everything to C# and let Roslyn do all the hard work.

You should fight that feeling. ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Why can't I have a semantic model to play with, like the big kids? 😔

@davidwengier davidwengier merged commit 4d80e6c into dotnet:main Dec 7, 2025
10 checks passed
@davidwengier davidwengier deleted the RenameCSharpWhenRenamingComponents branch December 7, 2025 21:25
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 7, 2025
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 is incorrect when done from a razor file

4 participants