Indentation depth incorrect in VS2022
strandloper opened this issue · 6 comments
When I have a C# class open in VS2022 and press Ctrl-E, D to format it, the document is correctly formatted with 4 space indents as I have configured for C# files. But this is a change so the file is now dirty and must be saved. But when I hit Ctrl-S to save it the file is reformatted with 2 space indents. I have disabled the extension so that it will no longer mess with my (and my colleagues') desired indentation.
I am a bit confused. The only thing which the extension is doing is to invoke the format command. It is exactly the same as you press ctrl e+d.
Is it possible that you have the .formatconfig file?
I was also surprised as I thought the behaviour should be the same as Ctrl+E,D.
No, not using a .gitconfig file.
.editorconfig
file perhaps?
.editorconfig
is a file where you could define how the code should be formatter and other good things. VS2022 should read that file out of the box and use the configurations there to format the code. The file should be placed at the root of the repository for global configurations.
.formatconfig
is a file which uses the .editorconfig
syntax to configure the extension per repository. The configurations there are with higher priority than the configurations in the VisualStudio. See the README at the bottom in this repository.
.gitconfig
is just for git and usually it lives outside of the repository. I am not aware that file to be used for any formatting of the code.
What I could say is that the behavior you are experiencing is very strange. Could you please try with another repository to verify it is a problem machine wide or it is specific to a repository?
I could have sworn that I typed .editorconfig, That is what I meant.
After experiencing this yesterday I disabled the extension. I just tested by enabling it, restarting VS2022 then starting a new solution in a new folder. The problem didn't reoccur in it so I opened the solution I was working on yesterday and tried on a few files; again the problem didn't reoccur.
Yesterday it happened in a file and I saw it happen but also in another where I didn't notice until viewing my pull request and seeing a lot more changes than I had made to the file; all because of whitespace differences.
But as you say, it shouldn't happen and I can't get it to happen again now, so I will close the issue and keep an out for it ever happening again.