codemaid
codemaid copied to clipboard
Wrong indent in class
Environment
- Visual Studio version: 2019 Community Preview 6
- CodeMaid version: 11.1
- Code language: C#
Description
When I upgraded VStudio to a preview version the first line of every class started to be indented with less space than other lines.
Steps to recreate
- updgrade VS 2019 Community to a Preview version
- have an .editorconfig with this values
# top-most EditorConfig file root = true
[*.{cs,config,aspx,ascx}] indent_size = 4 indent_style = space tab_width = 4
- create a class with some methods
- have the tabs spaces settings for all languages with empty values
- run the cleanup
Current behavior
It tabs all lines with 4 spaces, except the first line of the class which is indented with 2 spaces.
Expected behavior
All lines to be indented with 4 spaces
Thanks for reporting the issue. Indentation is handled directly by Visual Studio and we invoke their "Format Document" command. If you run Edit->Advanced->Format Document directly (i.e. without having CodeMaid do it) are you seeing the same indentation behavior?
For me I have notice on visual studio 2022 (64 bit) 17.0.1; CodeMaid - 12.0
- Right click => CodeMaid => Cleanup active document for C# class, indentation became 2 spaces.
- Click Edit => Advanced => Format Document on same C# class indentation is 4 spaces.
- Use hotkey ctrl + k then ctrl + d uses 4 spaces for indentation.
Before issue appear, I was changing config inside visual studio Tools => Options. Try to change indentation for HTML Razor view. Changed for, HTML, Racor, JavaScript, JSON, Web Form to indentation of 2. Then later change them back except Razor view.
For me, restart visual studio, CodeMaid's cleanup active document function back to normal, use 4 spaces for C# class.
This is an issue with VS, not CodeMaid. Happening now even without CM installed.
VS Pro 2022 (64 bit) 17.4.0 - CodeMaid VS2022 12.0.300
Same issue in reverse, just started happening in the latest version of VS.
VS formats to two spaces (as is preferred), CodeMaid formats to four (incorrect as per preferences).
I have tried altering VS settings, away from preferences then back again. We have an .editorconfig in place as well, that echos our VS preferences. I have also tried uninstalling and reinstalling CodeMaid.
We have a multi project solution, oddly CodeMaid is only acting out of step with VS on a couple of projects within the solution. I cannot find a configuration file that might casue this.
I am also experiencing this issue. I have spacing set to 2, and tabs are replaced with spaces.
Visual Studio's built-in Edit > Advanced > Format Document works as expected. CodeMaid's Format Document correctly uses spaces instead of tabs, but it formats each indentation level to 4 spaces.
This may be related to a bug I've been experiencing with the latest Visual Studio update, where creating new class files and using the quick actions (e.g. Ctrl+. to implement an interface) produces incorrect indentation.
EDIT: See this post on the Visual Studio Community Forums.
Thanks for the additional context. It sounds like Microsoft has acknowledged the issue and has a fix upcoming in Visual Studio.