-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
feat: improve scope detection and calculation #805
base: master
Are you sure you want to change the base?
Conversation
This is not the only reason. This is also needed to filter out single line scopes. There were a lot of other edge cases with this logic, I should have written tests for this.. In principle, I'm fine with the change, but it needs logic to filter single line scopes. And a lot of testing. |
The old behavior should be the default. I don't really want to add another option, maybe |
I have updated the code now so that the old behavior for one line scopes is the default and we only highlight one line scopes if The code still fixes the highlighting issue described in #799 for Does this look good to you? Or do you want to change anything else? If this looks good, I can try to add some tests too. |
This uses the exact cursor position to find the treesitter node used when finding the scope, which improves scope detection in Python, Lua and presumably some other languages too.
New behavior:
Old wrong behavior that the above fixes:
Importantly, it doesn't change the
language_for_range
calculation, which from what I can tell is the reason the other range was starting at column 0 of the current row.I also added an early exit to the scope calculation if the node didn't change (
TSNode:equal(TSNode)
tests that the nodes are in the same tree and the ids are equal), so we can skip the slightly slower calculations after that step (joining and going through tables). This should slightly speed up the calculation in a lot of cases (given all the auto commands used), but it is less important than the other change.This should close #799.