Edit → Format document replaces tabs with spaces when `indent_style = tab`
Version Used:
17.7 Preview 1
Steps to Reproduce:
Create a project with indent_style = tab in .editorconfig.
Note that Edit → Format document changes tabs to spaces. This looks like a recent regression.
The formatting analyzer then correctly issues a diagnostic that the code isn't correctly formatted. So "Format document" and "Formatting analyzer" are going against each other.
This is a transient/intermittent issue. I no longer reproduce after re-starting VS.
Closing for now. If it happened again, I'll re-open.
I have seen this again. But no repro steps since it's random with very low rate.
Hit it again today as well.
There was a similar issue but with a different feature previously https://github.com/dotnet/roslyn/issues/57323, which also reproduced randomly. Not sure if that would be related.
Hi, I have found a way to reliably reproduce this.
Steps:
- Tools -> Import and Export Settings -> Reset All Settings -> Pick Visual C#
- Edit -> Advanced -> Enable "View Whitespace"
- Tools -> Options -> Text Editor -> C# -> Tabs
- Tab size - set to 8
- Indent size - set to 8
- Select "Keep Tabs"
- Put the following in an .editorconfig
root = true
[*]
# (Please don't specify an indent_size here; that has too many unintended consequences.)
charset = utf-8-bom
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
indent_style = tab
- Put the following in Program.cs
namespace Foobar;
internal class Program
{
private enum FooBars
{
Foo,
Bar,
}
static void Main(string[] args)
{
FooBars switchThis = FooBars.Foo;
string returningThis = switchThis switch
{
FooBars.Foo => "Foo",
};
}
}
- Right click on "switch" and select "Add Both"
- The initial switch item and the added ones will all use spaces.
Notes:
Removing indent_size = 4 from the editorconfig results in tabs being used.
Having Tab size and Indent size in the settings as 4 results in tabs being used.
thanks Mike