Skip to content
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

Open
paul-schroeder-msft opened this issue Sep 13, 2022 · 6 comments · May be fixed by #10334
Open
Assignees
Labels
bug Something isn't working user story
Milestone

Comments

@paul-schroeder-msft
Copy link

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:

  1. Create a new Blazor solution
  2. Locate a .razor file that has a "@using" directive at the top
  3. Add a new folder named 'Whatever'
  4. Move the .razor file from its current folder into the new folder
  5. Respond 'Yes' when Visual Studio asks if you want to adjust the namespace to match the folder name

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
Razor file using directive gets extra spaces

@ghost ghost added the untriaged label Sep 13, 2022
@davidwengier
Copy link
Contributor

davidwengier commented Sep 14, 2022

@davidwengier
Copy link
Contributor

Not sure if this is the same as #6167? Seems like some of the duplicated reports for that issue, are actually this issue.

@davidwengier
Copy link
Contributor

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.

@DustinCampbell DustinCampbell added this to To do in 17.4 via automation Sep 15, 2022
@ghost ghost removed the untriaged label Sep 15, 2022
@DustinCampbell DustinCampbell added bug Something isn't working untriaged and removed untriaged labels Sep 15, 2022
@davidwengier davidwengier added this to To Do in 17.5 Preview 1 Oct 4, 2022
@allisonchou allisonchou removed this from To do in 17.4 Oct 5, 2022
@davidwengier
Copy link
Contributor

@ryzngard ryzngard moved this from To do to In progress in 17.5 Preview 1 Oct 13, 2022
@ryzngard ryzngard modified the milestones: 17.5 P1, 17.5 P2 Oct 25, 2022
@ghost ghost removed this from In progress in 17.5 Preview 1 Oct 25, 2022
@DustinCampbell DustinCampbell added this to To do in 17.5 Preview 2 via automation Nov 2, 2022
@DustinCampbell DustinCampbell removed this from To do in 17.5 Preview 2 Nov 3, 2022
@phil-allen-msft phil-allen-msft modified the milestones: 17.5 P2, 17.5 P3 Dec 22, 2022
@phil-allen-msft phil-allen-msft modified the milestones: 17.5 P3, 17.6 P1 Jan 10, 2023
@phil-allen-msft phil-allen-msft removed this from the 17.6 P1 milestone Feb 7, 2023
@phil-allen-msft phil-allen-msft added this to the 17.6 P2 milestone Feb 7, 2023
@ryzngard
Copy link
Contributor

ryzngard commented Mar 2, 2023

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

@phil-allen-msft phil-allen-msft modified the milestones: 17.6 P2, 17.6 P3 Mar 6, 2023
@davidwengier
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working user story
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants