-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Rainbow tree-sitter matches 🌈 #13530
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
base: master
Are you sure you want to change the base?
Conversation
This doesn't seem to work any more when rebased against latest changes. Is there a more up-to-date branch or repo with this feature? |
I don't see any issues after rebasing. Did you I carry this in https://github.com/the-mikedavis/helix/tree/driver - that may be more up-to-date than this branch at any given time since I rebase that often |
Yep, as you said there were no issues rebasing except a minor conflict in languages support doc. But, maybe, there's something wrong with how I built it or my config. |
Hmm, nope. |
If the rainbow colors aren't specified in a theme the base16 colors you have set for your terminal colorscheme are used. Maybe those aren't set and are defaulting to black. You can customize those colors in the theme when using this PR: Lines 133 to 140 in f4c43e6
|
After some research I seem to understand why things doesn't work for me. Thanks a lot for this great feature. Very sad that it takes so long to be reviewed and merged. |
@yerlaser please waste the time, it would be very insightful for all |
Basically it boils down to the fact that I am trying (still unsuccessfuly) to add support for moonbitlang and so my runtime folder is tainted. |
This is #2857 based on the tree-house bindings. (Recreated after that PR closed unexpectedly)
Configurable, themable, nesting rainbow highlights:
This approach uses the syntax tree to guide nesting levels and highlights so it ends up being much more flexible than a naive pair-matching implementation. For example, we can highlight
<
/>
when used in Rust type parameters likestruct MyStruct<'a> { .. }
and not mistakenly highlight<
/>
comparison operators. We can also capture multiple nodes, for example the#
,[
and]
characters in a Rust attribute like#[cfg(windows)]
and none of these characters are required to be adjacent.The cherry on top is that we can highlight according to the syntax tree's nesting information rather than whether characters surround each other. For example, in this TOML table,
characters
is a sub-table ofeditor.whitespace
and the rainbow highlights reflect that fact.It also works across injected languages like javascript injected into HTML script tags.
(You can see each of these things in action in the gif above.)
How does it work?...
This implementation leverages tree-sitter queries. We use a
QueryCaptures
Iterator very similar to the existing one for syntax highlights to query the parsed syntax tree for newrainbows.scm
patterns.Two new captures -
@rainbow.scope
and@rainbow.bracket
- track nesting level and capture syntax nodes for highlighting with rainbows. Specifically:@rainbow.scope
pushes aRainbowScope
on a stack. When@rainbow.bracket
matches, we test that the captured node is a direct descendant of the current scope. If it is, we emit highlights for it according to the scope's level of nesting.Configuration...
In the theme we add a
rainbow
key that takes a list ofStyle
s. You can have however many you want and you can re-use colors from the palette or even throw modifiers in there:A default rainbow using the red, yellow, green, blue, cyan, and magenta terminal colors is used as a fallback.
Enable the rendering of rainbow brackets in your
config.toml
Or enable rendering per-language in
languages.toml
(this overrides theconfig.toml
setting for any languages that set this value):When the
rainbow-brackets
option is disabled, rainbow brackets are not rendered or computed.Closes #695