-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve treesitter indentation #1440
Comments
Thanks for thinking about this, I like some of the ideas here about making use of tree-sitter to make auto indent more intelligent.
Am I understanding that this case covers if (thing)
{
something();
} Isn't this a stylistic choice? What happens if the brace is on the same line, does it outdent the whole void foo() {
if (thing) {
something();
}
} |
This means that we outdent every compound statement that's directly inside an if statement (note that the indentation of the if statement as a whole is not changed). My solution also works if the braces are on the same line (we obviously want to support all reasonable code styles). In your example, this looks like: // As it is a compound statement, the function body is indented one level
void foo() {
// The tail of the if statement should be indented one level, this would apply to the second line of the if statement.
// Because of the "outdent" definition, this is essentially nullified by the outdent of the compound statement.
// Even if they didn't cancel out, both of these would only apply starting from the second line
if (thing) {
// This is inside the body of another compound statement, so it's indented one more level
}
} The |
I'm opening this to continue the discussion from #1293. The current indentation configuration is somewhat limited and could be improved upon. For example, there is currently no way to write an
indents.toml
for C that handles:and:
correctly without breaking the rest of the indentation.
To make writing indent queries easier and more intuitive (right now,
indent
andoutdent
work differently which might be confusing), we could borrow some ideas from emacs as @archseer suggested.This still wouldn't be enough to fix the above issue, as that requires some sort of context-dependence. My suggestion is to also allow specifying a list of nodes in an indent query. The corresponding indentation will then only be applied if all of these nodes are directly nested in the given order. The
indents.toml
file might then look like this (for C):If we want to go in that direction, the current indent queries could easily be adjusted for this and eventually be updated to take advantage of the new features.
The text was updated successfully, but these errors were encountered: