Scan back to the containing syntax ancestor to compute highlights #3026
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.
This change starts the syntax highlight iterator before the
first visible byte of the source and then filters out highlights
which are not in the visible range.
The highlights iterator has some context that builds as it handles
tree-sitter QueryCaptures: locals/scopes tracking and the rainbow
matches nesting level. By starting at the start of the largest
containing node (if one exists), we can cover most cases where
locals tracking is noticeable and all cases for rainbow brackets
matching.
One edge-case remains for #1151: if the root node is
itself a
local.scope
, this change will not start far enoughback in the document to catch locals definitions which are out
of view.
For example, here's a fixed case for the locals tracking:
(source)
cursor
,captures
, andlayers
are recognized asvariable
(italic white) rather thanvariable.other.member
(blue) even though theirlocal.definition
is not within view. Some forsource
,range
andcancellation_flag
recognized asvariable.parameter
(underlined white) from the function's definition which is a few pages out of view.And this fixes the rainbow view problem: https://asciinema.org/a/507564