roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Code cleanup on save while resolving merge conflicts

Open vsfeedback opened this issue 2 years ago • 16 comments

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


[severity:It's more difficult to complete my work] [regression] [worked-in:VS2019] With turned on feature 'Code Cleanup on Save', while resolving conflicts after merging branches, after applying changes all 'using' directives are gone.


Original Comments

Feedback Bot on 4/18/2022, 01:41 AM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Apr 18 '22 19:04 vsfeedback

Very annoying, we must deactivate "Code Cleanup on Save" before resolving conflicts.

kakone avatar Jun 17 '22 17:06 kakone

I don't know if this is the only time it happens, but I have noticed that if you have conflicts in a project file it causes the project to be unloaded. If you are then reviewing conflicts in a file within that project then it loads the files from outside of the project i.e. with the path to file on disk. Which means the code cleanup does not have context and removes all using statements. This happens even in the diff window not just the merge window.

As a workaround, it may be possible that resolving project conflicts first prevents this from happening.

DavidJohnWilliams avatar Jul 22 '22 12:07 DavidJohnWilliams

Hi,

We have the same behavior.

Any news on this issue ?

MatthieuTruchet-VA avatar Aug 04 '22 07:08 MatthieuTruchet-VA

As a workaround, it may be possible that resolving project conflicts first prevents this from happening.

Unfortunately not. I didn't find any workaround apart from deactivating "Code Cleanup on Save".

kakone avatar Aug 09 '22 13:08 kakone

I am also facing the same problem, I found code cleanup feature very handy but for this problem I had to unable it.

AbdullahAlRana avatar Aug 18 '22 04:08 AbdullahAlRana

i'm having the same behavior

alexandresmoraes avatar Sep 12 '22 17:09 alexandresmoraes

Can confirm this is still a problem as of VS 2022 17.3.4. Very annoying bug.

waitwhereami avatar Sep 27 '22 13:09 waitwhereami

Confirming this is still an issue

l-e-f avatar Oct 31 '22 19:10 l-e-f

Still an issue, quite a big one (VS2022 17.3.6).

LiviuD avatar Nov 05 '22 12:11 LiviuD

Same issue using VS2022 17.4.1

mwasson74 avatar Nov 23 '22 17:11 mwasson74

Very annoying

mblichowski avatar Nov 29 '22 14:11 mblichowski

Same for me in VS2022 17.4.2.. 🙁

fredrikbergman avatar Dec 01 '22 07:12 fredrikbergman

Same here

andreatosato avatar Dec 06 '22 07:12 andreatosato

Note that this not only removes all using directives, but also breaks the code style of the merged file by ignoring rules defined in the EditorConfig file.

If someone needs steps to reproduce:

  1. Enable Options - Text Editor - Code Cleanup - Run Code Cleanup profile on Save
  2. Make sure that the chosen Code Cleanup profile formats the document and removes unnecessary usings.
  3. Do a Git merge that results in a conflict in a C# file.
  4. Resolve the conflict. Note that the preview of the resulting file in the lower part of the conflict window shows everything as it should be.
  5. Open the file after resolving the conflict.
  6. Note that all usings are removed from the file, which breaks the code.
  7. Also note that the formatting of the file was reset to the Visual Studio settings instead of the settings defined in the EditorConfig file.

cremor avatar Dec 06 '22 07:12 cremor

Same problem here, in VS 2022 version 17.4.2

EngWagner avatar Dec 07 '22 13:12 EngWagner

Our team is also seeing this issue. It's a big pain. Please fix. VS 17.4.0

randyshoopman avatar Dec 13 '22 17:12 randyshoopman

@JoeRobich Can we get a quick update on this? 🙂 Seems like lots of people are running into this (including myself! 😄)

Eli-Black-Work avatar Dec 21 '22 05:12 Eli-Black-Work

Include me in the list of people having this issue.

xania avatar Dec 21 '22 15:12 xania

If anyone is looking for a quick workaround, here's what I do:

  1. Make sure that the Add missing using directives on paste option is enabled (Tools -> Options -> Text Editor -> C# -> Advanced -> "Using directives" section)
  2. After the editor has stripped out your using statements, open the file and do Ctrl+A, Ctrl+X, Ctrl+V

Basically, copying and pasting the document on top of itself triggers the Add missing using directives on paste functionality, which readds most of the using statements 🙂

Eli-Black-Work avatar Dec 22 '22 02:12 Eli-Black-Work

@sharwell Sorry to message you directly, but is @JoeRobich still the correct person to be assigned to this, or could we get a status update? 🙂 Seems like a lot of people are hitting this, especially in the newer versions of VS.

Eli-Black-Work avatar Dec 22 '22 02:12 Eli-Black-Work

@JoeRobich

EngWagner avatar Dec 22 '22 16:12 EngWagner

@CSTI-IHarwell

EngWagner avatar Dec 29 '22 13:12 EngWagner

@EngWagner I'm guessing they're probably on Christmas or New Year's vacation 🙂

Eli-Black-Work avatar Dec 30 '22 02:12 Eli-Black-Work

If anyone is looking for a quick workaround, here's what I do:

  1. Make sure that the Add missing using directives on paste option is enabled (Tools -> Options -> Text Editor -> C# -> Advanced -> "Using directives" section)
  2. After the editor has stripped out your using statements, open the file and do Ctrl+A, Ctrl+X, Ctrl+V

Basically, copying and pasting the document on top of itself triggers the Add missing using directives on paste functionality, which readds most of the using statements 🙂

This is unfortunately not working for me, first I have to find the file first which is the hardest part because I always forget the name of the file and regret it immediately after hitting the accept merge button.

xania avatar Dec 30 '22 15:12 xania

I also have this annoying issue. Visual Studio Professional 2022 (64bit) 17.4.3

AleksTem avatar Jan 03 '23 12:01 AleksTem

Also suffering from this. It's also not only when resolving merges, VS always removes all using directives except System ones when I run code cleanup.

Carl-Granstrom avatar Jan 24 '23 12:01 Carl-Granstrom

I literally created an account on github just to thumbs-up this post, though my whole team has been dealing with this since last year. Visual Studio Professional (64 bit) 17.4.4

et3rnalcynic avatar Jan 27 '23 15:01 et3rnalcynic

I'm using CodeCleanupOnSave extension, which has the same functionality, but no such issue. It is very strange that this issue is still present after almost a year. It is also funny that it's an extension by Mads Kristensen :) .

Dreamescaper avatar Jan 27 '23 16:01 Dreamescaper

Hi @sharwell, now that it's after Christmas/New Year's vacation, can we confirm that @JoeRobich is the correct person to be assigned to this?

It seems this is affecting a lot of people, and there hasn't been any visible activity from @JoeRobich since April 20th, 2022 😄

Eli-Black-Work avatar Jan 30 '23 03:01 Eli-Black-Work

Hi @sharwell, now that it's after Christmas/New Year's vacation, can we confirm that @JoeRobich is the correct person to be assigned to this?

It seems this is affecting a lot of people, and there hasn't been any visible activity from @JoeRobich since April 20th, 2022 😄

And that activity in April was not even by Joe, it was by @jinujoseph who assigned Joe to this... 🤯

mwasson74 avatar Jan 30 '23 14:01 mwasson74