Skip to content

Comments

Add willRenameFiles support, and an abstraction for extenders to implement#81549

Merged
davidwengier merged 5 commits intodotnet:mainfrom
davidwengier:willRename
Dec 5, 2025
Merged

Add willRenameFiles support, and an abstraction for extenders to implement#81549
davidwengier merged 5 commits intodotnet:mainfrom
davidwengier:willRename

Conversation

@davidwengier
Copy link
Member

Part of dotnet/razor#8541

Adding functionality to Razor so that when a .razor file is renamed, the relevant component tags and any C# references are updated, so need willRename support. Since its a workspace request, if we implement it then Roslyn won't be able to, so best to support it in Roslyn and delegate to Razor as required.

@davidwengier davidwengier requested a review from a team as a code owner December 5, 2025 00:34

foreach (var listener in renameListeners)
{
var edit = await listener.Value.HandleWillRenameAsync(request, requestContext, cancellationToken).ConfigureAwait(false);
Copy link
Member Author

Choose a reason for hiding this comment

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

Rather than have Roslyn bother to handle globs, and deal with the complexity of one willRenameFiles request possibly containing multiple files that multiple handlers would want to know about, it seemed easier to just have each handler check the actual files being renamed and see if they care. They'd want to do it anyway.

};
serverCapabilities.ImplementationProvider = true;

if (clientCapabilities.Workspace?.FileOperations?.WillRename ?? false)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Just discovered that myself. Was very easy to move over though :)
VSCodeRazorFile

@davidwengier davidwengier merged commit 3c291cc into dotnet:main Dec 5, 2025
26 checks passed
@davidwengier davidwengier deleted the willRename branch December 5, 2025 23:42
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 5, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
davidwengier added a commit to dotnet/razor that referenced this pull request Jan 7, 2026
#12561)

Fixes #8541
Fixes #11493

Needs dotnet/roslyn#81549 before this will
build, but Roslyn CI seems to be having issues, so putting this up while
we wait.

This implements `workspace/willRenameFiles` support in our LSP server,
so that when a `.razor` file is renamed, we perform a full rename of the
component, including updating component tags and getting Roslyn changes
for renaming the class name. In VS we also include a poly-fill since
`willRenameFiles` is not supported, and an extra "apply rename" method
to fill in the difference between real `willRenameFiles` support, where
edits are made _before_ file renames, and our polyfill which lets CPS
handle the file rename, and applies the edits afterwards.

VS:

![VSRenameRazorFile](https://github.com/user-attachments/assets/fba5a0af-a0ad-4814-ad4b-2649360bbd07)

VS Code:

![VSCodeRazorFile](https://github.com/user-attachments/assets/a9174022-42b8-45a9-b4d4-0b2b32495e02)
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