Skip to content
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

Scan back to the containing syntax ancestor to compute highlights #3026

Conversation

the-mikedavis
Copy link
Member

@the-mikedavis the-mikedavis commented Jul 10, 2022

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 enough
back in the document to catch locals definitions which are out
of view.


For example, here's a fixed case for the locals tracking:

Before After
before after

(source)

cursor, captures, and layers are recognized as variable (italic white) rather than variable.other.member (blue) even though their local.definition is not within view. Some for source, range and cancellation_flag recognized as variable.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

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 locals tracking: if the root node is
itself a `local.scope`, this change will not start far enough
back in the document to catch locals definitions which are out
of view.
@archseer
Copy link
Member

There can be a lot of highlight nodes though. I'm thinking we should maybe scan certain queries over the whole document/wider area/parent node, but limit highlights to just the visible range. That would require two cursors though, then merging the two iterators at scan time.

@the-mikedavis
Copy link
Member Author

Yeah good point, I don't really like the wasted effort either

I'll give it a go using a separate iterator and merging the two 👍

@the-mikedavis the-mikedavis deleted the md-scan-backwards-highlight-iterator branch July 10, 2022 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants