-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename namespace results in extra spaces for @Using directive when moving .razor files #6830
Comments
This was also reported in https://developercommunity.visualstudio.com/t/VS2022-171-Blazor-moving-razor-files-fr/10011429 and https://developercommunity.visualstudio.com/t/Refactoring-namespaces-corrupts-Razor-so/10041958 I can repro this in latest VS |
Not sure if this is the same as #6167? Seems like some of the duplicated reports for that issue, are actually this issue. |
So we're getting a didChange notification, coming from Roslyn which ultimately comes from Project System which gets its list of changes from Roslyn! So the next step is to see whether Roslyn is making strange changes (adding whitespace when it should be changing a using statement???) or whether its our source mapping service (which would be called by Roslyn to translate the changes to the .g.cs file to the .razor file) doing something odd. I suspect nothing else in our system is relying on didChange notifications for .razor files, so we could potentially just (somehow) tell Roslyn not to apply workspace changes to our mapped documents and avoid the issue entirely for now, but obviously fixing things is better, because actually having the using statement change namespace would be magical. |
This is because of formatting done by Roslyn. Razor emits code like // some global usings
namespace MyRazorApp
{
// @using System
using System; // note indentation (or lack thereof)
} So when the formatting pass happens it indents the using statement |
Describe the bug:
When you move files (i.e. Blazor/razor files) into a subfolder in Visual Studio, it asks whether you would like to rename the file namespace to match the folder structure. If you answer "yes", then whatever does the adjustment adds an extra tab after the "@using" statement at the top making it “@ using” and leading to a compilation issue. There are also reports this will freeze on large projects when, for example, you move a large folder of files.
Version used:
e.g. VS2022 17.3 or 17.4
To reproduce:
Steps to reproduce the behavior:
Expected behavior:
The namespace adjusts, but the space between the "@" and "using" remains as-is
Actual behavior:
The namespace adjusts, but space is inserted between the "@" and "using", resulting in a compiler error.
Additional context:
See attached image
The text was updated successfully, but these errors were encountered: