codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Wrong indent in class

Open tomy41 opened this issue 4 years ago • 2 comments

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

  1. updgrade VS 2019 Community to a Preview version
  2. 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

  1. create a class with some methods
  2. have the tabs spaces settings for all languages with empty values
  3. 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

tomy41 avatar May 15 '20 14:05 tomy41

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?

codecadwallader avatar May 30 '20 11:05 codecadwallader

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.

Nness avatar Dec 01 '21 02:12 Nness

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.

kim3er avatar Nov 15 '22 11:11 kim3er

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.

Wildenhaus avatar Nov 22 '22 00:11 Wildenhaus

Thanks for the additional context. It sounds like Microsoft has acknowledged the issue and has a fix upcoming in Visual Studio.

codecadwallader avatar Dec 11 '22 17:12 codecadwallader