Roslyn: Code formatting breaks briefly after code is fixed

Created on 24 Sep 2019  路  7Comments  路  Source: dotnet/roslyn

Version Used:
Roslyn (Language Service)
3.3.1-beta3-19454-05+3b423bd305daf81076d4d7b105101361c2

Steps to Reproduce:

  1. Put a C# file into a non-compilable state briefly and fix it. ie, a simple if block condition
  2. Hit enter. The cursor isn't aligned to the expected location

Expected Behavior:
Correct indentation

Actual Behavior:
Only indents once

Tabs are used for all indenting in this file.

incorrect_formatting_csharp

4 - In Review Area-IDE Bug

Most helpful comment

I have a potential fix. Testing now.

All 7 comments

This is reproducible on both VSwin and VSmac

cc @CyrusNajmabadi

Definitely doesn't seem desirable :) I can look to see if we can figure out where indentation/smart-indentation is going off the rails here.

Note: this depends on using 'tabs' for indentation. Indentation works properly if you are set to 'spaces'. No clue why this would affect anything.

Repro:

Ensure only tabs are used for indentation:

c# public class Example { public void Test(object session) { if (session == null)return; } }

Hit enter between ) and return.

return is then indented 3 spaces instead of 3 tabs. There is likely some sort of conversion internally that is just computing "3 indents" but then converting that to just 3-spaces instead of the proper actual indentation.

Great bug!

I have a potential fix. Testing now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AdamSpeight2008 picture AdamSpeight2008  路  3Comments

ashmind picture ashmind  路  3Comments

NikChao picture NikChao  路  3Comments

MadsTorgersen picture MadsTorgersen  路  3Comments

vbcodec picture vbcodec  路  3Comments