Fix else indentation after array literal
It is for bug introducted by me, where the else get incorrect indentation if if has an [] in the condition. For example:
if (true)
{
if (args[0])
{
}
else
{
}
}
(else tries to find the indentation of the last if but it is removed from the indentation stack).
When exactly was the issue introduced and can we solve this by further adjusting that change?
Here: https://github.com/dlang-community/dfmt/pull/554, d862d8aef1b46289be1fc7cf80809b70a734e8fa
I tried to find a better solution but came up with this. Probably I could look again at it, maybe I get a fresh idea.
The problem here is that else is indented same as if. The formatter when it sees an else looks for the last if on the indentation stack and puts the same amount of spaces as for if. My commit above removes the if-indentation from the stack because it breaks the array literal indentation.
There are actually a few constructs, that are normally indented the same, independently of braces before. One of them is array literals:
if ((((([
// One level indentation here, even if I'm in `if` or after braces.
])))))
Another one is probably multiline lambdas, they have a lot of indentation problems currently in arguments and other constructs
if (f((x, y) => {
// One indentation level here.
}));
So indentation stack is cleared for such constructs. But after the construct, other code can follow that should be indented and there is a need to restore the indentation stack to indent the code after such thing.
Therefore I came up with this array of indentation stacks, where I can save any amount of indentations (recursively) and restore them after a specific construct ends.
Well after some testing I've found a different solution; the tests are left unchanged. I kept the first commit for comparision, but can do a squash.
feel free to squash yourself, would otherwise squash merge
Sure, done.