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

Code CleanUp - Remove unnecessary Using - removes usings from files not in loaded projects/solution #60867

Open
vsfeedback opened this issue Apr 20, 2022 · 6 comments
Assignees
Labels
Area-IDE Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] [regression] [worked-in:17.1 Preview 1]
Hi,
In the Code Cleanup 'Remove unnecessary usings' removes needed imports(VB.Net) when doing a TFS-Diff of a File not in any loaded projects.
So if I use a new VS instance to check the changes from a merge, and have the new option 'Code Cleanup on Save' activated, then the Code CleanUp gets executed after resolving Conflicts, and sometimes removes needed Imports (VB.Net, keyword using in C#).
In Version '17.1 Preview 1' and earlier I used a extention to call 'Code Cleanup on Save' and this didn't happen at that time, it only started happening after installing '17.1 Preview 2' and activating the integrated 'Code Cleanup on Save'-Feature


Original Comments

Feedback Bot on 1/20/2022, 10:32 PM:

(private comment, text removed)

Feedback Bot on 1/21/2022, 09:48 AM:

(private comment, text removed)

Alexander Wurzinger on 3/10/2022, 02:46 AM:

(private comment, text removed)

Jose Mira on 3/11/2022, 08:27 AM:

(private comment, text removed)

Alexander Wurzinger on 3/11/2022, 09:49 AM:

(private comment, text removed)

Coffee on 3/27/2022, 11:02 PM:

(private comment, text removed)

Coffee on 4/11/2022, 05:45 AM:

(private comment, text removed)

Jorge Durán on 4/12/2022, 00:42 AM:

(private comment, text removed)

Coffee on 4/13/2022, 01:28 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 20, 2022
@JoeRobich
Copy link
Member

The issue seems to be that VS is configured as the git mergetool and the user is resolving conflicts in C#/VB.NET files that are not part of a loaded Project. The CodeCleanup routine fires when this file is saved and Roslyn is applying fixes to this loose document.

Proposed fix: In CodeCleanup, check that the document is part of a loaded Project (not miscellaneous workspace) before applying fixes.

@FelixDamrau
Copy link

Unfortunately, this is not the case with me.
Maybe I'm not understanding you correctly, but that's how it is with me:

I have opened a solution/multiple project files.
I start a merge and resolve a merge conflict within Visual Studio. All files involved belong to one project of the Solution.
As soon as I accept the resolution of the conflict usings disappear.

@Lohnegrim
Copy link

@FelixDamrau, I saw the same with TFS-Merge. (My VS is configurated to use Visual Studio Team Fundation Server as Sourcecontrol)
I assume that VS (sometimes) threads the Temporaery File created for the Merge as a File not part of any project, and executes the cleanups on them.
Do my unserstanding the temproaery file is only created for Merging, so in a Diff Window the CleanUp works correctly.

Remark:
I noticed that the Public comments were declared as private comments when this issue was created?

@FelixDamrau
Copy link

Lohnegrim
I assume that VS (sometimes) threads the Temporaery File created for the Merge as a File not part of any project, and executes the cleanups on them.

That sounds plausible.

@jinujoseph jinujoseph added Concept-Continuous Improvement Developer Community The issue was originally reported on https://developercommunity.visualstudio.com Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead Concept-Continuous Improvement labels Apr 28, 2022
@jinujoseph jinujoseph added this to the Backlog milestone Apr 28, 2022
@RapGeneral
Copy link

+1, this issue is very annoying. As someone who uses code cleanup a lot, in order to keep my code tidy, its very frustrating when I forget about this bug and merge... VS does not have an option to import all missing usings, and for big files that usually have a lot of imports its a very big pain to add them back. Please prioritise fixing this.

@CyrusNajmabadi
Copy link
Member

@RapGeneral this is on the backlog. But if it's something you are passionate about, we would likely take a community pr here if you wanted to contribute it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com
Projects
None yet
Development

No branches or pull requests

7 participants