Roslyn: Add "fix namespaces" action that applies to all files in a Solution Explorer node

Created on 24 Jul 2019  路  7Comments  路  Source: dotnet/roslyn

This was mentioned in https://github.com/dotnet/roslyn/issues/14341#issuecomment-489984793, and I'm filing a new issue to raise it as its own request. It was initially not implemented due to performance issues, however it comes up often for me. I use ReSharper to get it done.

Scenarios where I commonly use this feature:

  1. I have ten or so C# files I need to copy from one GitHub repository to another. I copy and paste the files into the file system where I want them. Now I want to fix the namespaces to fit the target.

  2. I have a bunch of files I鈥檝e inherited where some classes are in proper namespaces, some are in the wrong namespace, and some lack namespaces completely.

    • Not covered by https://github.com/dotnet/roslyn/issues/37243 because there's no clear way to trigger the action when no files are being moved. (https://github.com/dotnet/roslyn/issues/37243 focuses on keeping namespaces correct rather than correcting namespaces.)

Note that in the scenarios I personally encounter, I don't need Visual Studio to tell me when the namespace doesn't match--I know when I need/want to apply this action.

Expected behavior:

  1. I right-click on a solution explorer node and select the "fix namespaces" ("adjust namespaces") action.
  2. (Optional) I get prompted to provide any clarifying info, and see a list of files that will be changed.

    1. I click OK.

  3. The namespaces within that node are adjusted and known references to them are changed to match.

/cc @mikadumont

Area-IDE Feature Request InternalAsk

Most helpful comment

@ryzngard The analyzer work will cover diagnostic in the error list with a fix all code fix across a project or solution. But we will need to create a UI gesture in Solution Explorer for this.

All 7 comments

cc @genlu

cc @ryzngard

@genlu @mikadumont is this handled by work for analyzer?

It will be good if the similar option will be provided on project level and folder level also.

It will be good if the similar option will be provided on project level and folder level also.

I agree, I would not consider this issue completed unless this is the case. Having to go through 10 (first scenario) or a bunch (second scenario) of files and individually click on each of them would mean I'd still use ReSharper for this. This is what I'm driving at when I say "right-click on a solution explorer node" in the expected behavior.

is this handled by work for analyzer?

I'd be interested to hear what might handle this. I'm happy to read through another issue to see if its solution applies here and add more details to the description if it doesn't seem like it to me. (My main focus being the UX--can it replace my ReSharper usage--rather than how it's implemented.)

@ryzngard The analyzer work will cover diagnostic in the error list with a fix all code fix across a project or solution. But we will need to create a UI gesture in Solution Explorer for this.

Also make sure we include if a folder is renamed in solution explorer. From https://twitter.com/sarathi4ever/status/1276646523283976193?s=20

Was this page helpful?
0 / 5 - 0 ratings