jeudi 2 septembre 2021

broken indentation formatting when if/else chain is over 100 lines in length - visual studio 2017 C++

While using Visual Studio 2017 v15.9.35 I noticed that for functions with long if/else chains the indentation would break at some point. After some experimentation I was able to figure out why; when the if/else chain is over 100 lines in length (from the first if() line) the formatting breaks.

//under 100 lines with expected behavior

void test()
{
    int x = 10;
    if(x == 10)
    {
        x = 11; 
    }
    else //when you press enter twice the closing bracket is in the correct position
    {
        x = 12;
    }
}

//>= 100 lines

void test()
{
    int x = 10;
    if(x == 10)
    {
        x = 11;
        x = 11;
        ... repeat 95 more times (97 in total)
    }
    else //when you press enter twice the formatting breaks
    {
    x=12;
}
}

After this happens all new lines of code are misaligned by 1 tab which gets really annoying. The example I gave is unrealistic but easy to reproduce, in a real scenario just reaching 100+ lines cumulatively (not just in a single block) causes the same behavior. I was wondering if this is a bug or if there is some setting I can adjust or plugin I can install to get the correct behavior. I'm aware that refactoring the code by moving the block code into separate functions to reduce the overall length is an option too, but this is not always the most desirable solution. I was going to report this on https://developercommunity.visualstudio.com/ as well, but I'm not sure if 2017 is still supported.

Also just to reiterate, the question is: Is this a bug or is there some setting I can adjust or plugin I can install to get the correct behavior.

Aucun commentaire:

Enregistrer un commentaire