Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Move indent right one when the highlighted line is a scope start/end #77762
Previously, the indent was always to the left of the current line.
In general, this works:
However, there are still edge cases where this does not work correctly, since it's not really semantic, it's just based on the indentation of the above and below lines.
This is a relative edge case, and this should solve the problem in most codebases, but not all. The correct solution of course is to find the indents based on semantics, which is what #49342 is about, so I don't think this actually closes the bug totally, and so suggest it remain open. However, solving that problem is a bigger task, and requires a large amount of changes in the model, so in the meantime I think this is a good stopgap, and anyways is an appropriate fallback for plain text and unknown syntax.
Where begin/end scope is ambiguous, for instance in yml, where there aren't really "end scopes" per se, it prioritizes it as a begin scope:
There is strange behavior when the configured indents don't line up with the indents in the source. These are hidden by the current behavior, but now my PR exposes them in a weird way.
This makes the odd behavior a bit more obvious, but I think the underlying issue is that the indent detection isn't semantic anyways, it's entirely based on the number of spaces compared to the configured indent size. The issue here is that a, b, c, d, and f (but not e and second a) are in the 0th scope, and e and second a are in the 1st scope, because tab settings are set to 4 spaces. I'm not sure what to do about this.
I should also mention that this will not do the appropriate indentation in Allman's style if the line above the
Previously, the indent was always to the left of the current line. While this logic was easier to implement, it is inconsistent with the behavior expected. This commit changes it to select the scope, rather than the line's indent. This is not a complete fix for #49342, as this does not add support to semantic detection, however, this will work in probably 90% of the cases, and is a relatively straightforward fix.