-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Sync namespace to folder reformats the entire document #34707
Comments
I noticed that (at least for me), it even formats based on rules which are marked as silent in .editorconfig. To be precise, i have: csharp_prefer_braces = false:silent in my editorconfig, and fixing the namespace removes all braces for single line statements. This breaks the feature for me |
Roslyn does not have a feature to remove braces (see #29606 for a request to add it). I have no idea how/what/why you observed this. |
Also, i dont think i have any code cleanup or formatting options defined which do this for me automatically (on save or by hotkey or whatever), which is why it confuses me even more. The only way to do this normally in my setup is to move the cursor to the braces and use the "remove braces" refactoring it offers there. |
@sharwell if someone puts ont he simplifaction annotation on code, this is a simplification that can happen. That happens so that someone can use the normal SyntaxGenerator codepaths but end up with blocks that match their "allow preference" here: If its the case that sync-namespace is adding teh simplification annotation (for example, to shorten type names post-move) then this might fall out because of it. |
Ah, i understand. Thanks for the info! Sorry to bother again, but could you give me any hints at how i can disable this feature for this specific option? The option is allready set to "silent", which seems to be the lowest severity? I also would like to keep all the other code style options on and also apply them on code generation if possible |
|
I have to revoke my last comment. The brace removal started again. I cannot figure out why it happens sometimes and sometimes not. |
I opened a bug that was de-duped against this one. In my case, I drag-n-drop a source file to a new folder, which updates the C# namespaces to match the folders - in doing so, it re-formats the file, and changes all of my tabs into spaces, even though that's not the setting. This feels similar to:
|
Note that the desired behavior here is the Sync Namespaces feature should not make any alterations to the formatting within the document. The only changes that should be made are the introduction or removal of qualified names, e.g. |
My VS feedback was also duped against this. The feature is unusable for me and I must be careful not to accept the offer to adjust namespaces when moving files to another folder. It will do that, but it also does other offensive things, like removing all braces with single instructions content. So this is open for years?! Guess the namespace update has only recently been added to VS so I only noticed this now. I'm not sure what preferences I've set in Visual Studio, hopefully none. Everything should be controlled exclusively through .editorconfig files, they're way more manageable. And if it says I have no preference about braces, it means that I will decide individually. The editor then has no right to change this. Even more so when it claims it will only change the single namespace line. Why does it even have to touch any other line of the document that has nothing to do with that? The whole feature seems to be out of control here. |
@ygoe The feature needs to update code to keep the semantics when it moves from one namespace to another (you can imagine how certain names would now mean something else if it didn't do that). However, the primary mechanism it uses to perform that work is to 'expand' the code to have it's fully-qualified meaning, and then 'simplify' it back to the reduced form people normally type. Unfortunately the subsystem it uses for that makes a lot more changes along the way beyond just the name expansion/simplification. If you're interested in helping us improve this, we'd happily work with you and we'd accept community PRs here. Thanks! |
Understood. I will make sure I'm not using this trap feature until I'm able to repair it myself. Which may take a long time. |
Version Used:
2019 RTM
Steps to Reproduce:
Expected Behavior:
Actual Behavior:
I cannot use this feature in any test project as it breaks all tables. Why does it need to reformat the document to fix the namespace?
The text was updated successfully, but these errors were encountered: