Move indent right one when the highlighted line is a scope start/end #77762
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 (or a rough
proxy of that), 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.
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.
For what it's worth, this does work in Notepad++ at least:
![image](https://user-images.githubusercontent.com/647786/61653842-81ea7980-acbb-11e9-8ad5-52fdb4bea9e3.png)
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.
Current version:
My version:
![image](https://user-images.githubusercontent.com/647786/61645230-835d7700-aca6-11e9-885e-e04b3156e30a.png)
![image](https://user-images.githubusercontent.com/647786/61645249-8b1d1b80-aca6-11e9-9959-df69fa8981c2.png)
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
{
is selected, as mentioned in #53737, but I think that's probably ok, as correct behavior will be seen if the bracket is selected.