Rename a .razor file when Roslyn renames the component type name#12606
Rename a .razor file when Roslyn renames the component type name#12606davidwengier merged 8 commits intodotnet:mainfrom
Conversation
|
|
||
| namespace Microsoft.VisualStudio.Razor.LanguageClient.Cohost; | ||
|
|
||
| using Rename = Microsoft.CodeAnalysis.ExternalAccess.Razor.Cohost.Handlers.Rename; |
There was a problem hiding this comment.
Out of curiosity, which change made the using changes in this file necessary?
There was a problem hiding this comment.
Something in Roslyn changed, I can't remember the exact thing that conflicted, but the Roslyn version bump alone introduced the issue.
| if (classDecl.Parent is null || | ||
| classDecl.Parent.GetLeadingTrivia() is not [{ } firstTrivia, ..] || | ||
| !firstTrivia.IsKind(CodeAnalysis.CSharp.SyntaxKind.PragmaChecksumDirectiveTrivia) || | ||
| firstTrivia.ToString().Split(' ') is not ["#pragma", "checksum", { } quotedRazorFileName, ..]) |
There was a problem hiding this comment.
From my quick debug, there are 3 more, which makes me wonder if this would just be being a little too fussy about what the exact code gen should be. I think what does make sense though, now that I think about it, is validating that quotedRazorFileName is actually a .razor file name.
In other words, I don't think we should necessarily care here if the compiler starts emitting more leading trivia (eg, suppressing some new C# compiler warning), or if the .NET 9 compiler emits 3 bits of trivia and the .NET 10 compiler emits 4. If we find a pragma we can use, we should use it IMO.
| } | ||
|
|
||
| var razorFileName = quotedRazorFileName.Trim('"'); | ||
| var newFileName = Path.Combine(Path.GetDirectoryName(razorFileName), newName + ".razor"); |
There was a problem hiding this comment.
If we get here and the extension from that is anything but .razor, then just about every other assumption we have about the world is probably wrong too. But I'll add an assert just in case :)
Part of #8541
Responds to Roslyn renaming C# symbols, and if it's a Razor component, defined in a Razor file, then it renames the file (and associated files)
Needs a Roslyn bump to get the notification interface, but I'm putting this up or I'll lose track of the branch until next year :)