Open Danielkonge opened 8 months ago
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.
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.
Just to make sure that I understand how you would want it to work.
My update gives behavior like this, since the scope is inside the function:
The master branch gives behavior like this:
Do you want an option to keep the old behavior? E.g., something like one_line_scope
(maybe with a better name)? Because I would at least prefer to have an option actually underlines even for one line scopes. (I could underline the exact scope range in those cases too then.)
When I better understand the behavior you would want I can update this, and then I can add some tests after you have looked at it. (I would like to know if the code makes sense to you before adding the tests.)
Do you want an option to keep the old behavior?
The old behavior should be the default. I don't really want to add another option, maybe show_exact_scope
can also enable single line scopes with just underline.
The old behavior should be the default. I don't really want to add another option, maybe
show_exact_scope
can also enable single line scopes with just underline.
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 show_exact_scope
is true.
The code still fixes the highlighting issue described in #799 for show_exact_scope
both true and false.
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.
When is this being merged to the main branch?
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.