-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 indent queries for python #5332
Conversation
where the tree-sitter completely fails to parse incomplete code.
Looks good to me! It misses the case of nested-try statements, but I understand that the PR isn't supposed to handle every case. I do have a bit of reservation about the latter two queries being a bit too ad-hoc though.
Maybe we should somehow match for a "try" in there too. |
I think there's some value in keeping the patterns as generic as possible. This way, we also handle situations which we haven't specifically thought about. Since the patterns only match
This would definitely not break anything but it will probably miss some situations where the grammar produces a slightly different pattern. Also, it would be very sensitive to small changes in the grammar. For example, the version of the grammar in the playground only creates a single Handling nested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, that's a pretty cool way of working around it. Thanks!
where the tree-sitter completely fails to parse incomplete code.
where the tree-sitter completely fails to parse incomplete code.
This is a workaround for the python tree-sitter grammar being very sensitive to incomplete code in some cases (an
try_statement
without an except/finally clause sometimes even prevents the surrounding function from being recognized). I simply added a few queries that improve the indentation in common situations. Since they only matchERROR
nodes, this shouldn't break anything that works correctly right now.Should fix #763 and #5045. At least for the common scenario of writing down a
try_statement
with a missingexcept_clause
/finally_clause
, the indentation is now correct in all cases I tested,