Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is curly brace indentation messed up in Visual Studio 2015?

I'm using the Visual Studio 2015 Release Candidate.

In previous versions of Visual Studio I've always programmed with both Automatic brace completion and Automatically format completed block on } disabled.

In previous versions when creating a block, the curly braces were automatically formatted when typing enter { enter }

Which would result in:

class Foo
{
}

In VS 2015 that results in:

class Foo
{
    }

Is there a new setting I'm missing or is this a bug in the RC?

like image 803
inline Avatar asked Jul 01 '15 03:07

inline


1 Answers

Okay, I tested it out. The result seems rather obvious - you told Visual Studio not to format your code on }, so it doesn't do that.

In other words, the behaviour in the older Visual Studios seem to be broken - even though you've specified you don't want VS to do the formatting for you, it does. After all, as you're typing, your cursor ends up on _ here:

class Test
{
    _

Then you just add a }, so it's

class Test
{
    }

Which older Visual Studio automatically formats as

class Test
{
}

even if you have unchecked Automatically format completed block on }. This is obviously auto-formatting - if you press Ctrl+Z, it will revert the formatting, not the } itself. Arguably, the behaviour in VS2015 is a fix of a bug present in the old versions.

This becomes much more apparent when I start using crazy formatting with your settings. Code like this:

class Test
{
    public
        string
            Ana
    {
        get; set;
        }
    }

Becomes

class Test
{
    public
        string
            Ana
    {
        get; set;
        }
        }

on VS2013! This is obviously wrong. On the other hand, VS2015 correctly applies no formatting - it simply positions your caret at the place it thinks you want it, and doesn't apply any formatting automatically, ever.

So, is there a way to get to the old behaviour? Nothing simple, I'm affraid - my guess is that MS simply considers to be the proper behaviour, and the old one being buggy, and it's hard to argue with that. There's some workarounds you could do to get closer to the old behaviour, like manually disabling all the auto formatting except for the brace alignment, but it will still change the behaviour a bit.

Still, I can see how the behaviour you expect would be desirable. If you think it's worth it, you could try filing it as a bug on Connect, though I wouldn't give it much of a chance of being "fixed" - IMO it's a fix to a bug, not a bug.

like image 91
Luaan Avatar answered Sep 29 '22 08:09

Luaan