dotnet/roslyn

Text Editor: wrong indention

Open

#30,531 opened on Oct 16, 2018

View on GitHub
 (2 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-IDEBugDeveloper CommunityIDE-Formatterhelp wanted

Description

Hi,

I have 2 annoying issues with indention reproducible in VS 2015, VS 2017.

I reset all options in VS and opened a C# file.

If I don't correct what VS is trying to help, I get this.:

public xxx()
{
    if (Smth)
        ZZ = 8;
    else
        if (Res)
    {   // <= wrong indention

    }   // <= wrong indention
}

I don't use braces if have only one code line after 'if'.

  1. another issue:

In Options I disabled 'Automatic brace completion' under Text Editor / C# / General because I don't like it in some cases.

But then I get this results:

void xxx()
	{   // <= wrong indention
	if (Smth)
		{   // <= wrong indention
	}
	else
		{   // <= wrong indention
	}
}

Regards

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/334246/text-editor-wrong-indention.html VSTS ticketId: 682797 These are the original issue comments:

hwo-news on ‎9‎/‎12‎/‎2018, 06:27 AM (33 days ago): Hello Microsoft,it doesn't make sense if I describe my problem and you eliminates the important leading whitespaces which are needed to understand this problem!I will resend my problem with screenshots.Regards Rock Li - [MSFT] on ‎9‎/‎14‎/‎2018, 02:38 AM (31 days ago): Hi hwo-news, Thank you for your feedback! According to your picture and description, I found that "else" with "if" is a whole, whether you press or not "Enter" between "else" and "if", the "{ }" will still show as pictures, in other words, the"{}" starting location will follow starting locations of "else" or "else if". instead of "if", because in there, "else" and "if" is a whole, in addition, you can check the code formatting by "Ctrl+K, Ctrl+D". Please feel free contact us if you have any question.We look forward to hearing from you!P1:

These are the original issue solutions:

hwo-news solved on ‎9‎/‎14‎/‎2018, 08:50 AM (31 days ago), 0 votes:

Contributor guide