Support bracket colorization (rainbow brackets)#43172
Conversation
Co-authored-by: MrSubidubi <dev@bahn.sh> Co-authored-by: Lukas Wirth <lukas@zed.dev>
Co-authored-by: MrSubidubi <dev@bahn.sh> Co-authored-by: Lukas Wirth <lukas@zed.dev>
Co-authored-by: MrSubidubi <dev@bahn.sh> Co-authored-by: Lukas Wirth <lukas@zed.dev> # Conflicts: # crates/project/src/buffer_store.rs
Co-authored-by: MrSubidubi <dev@bahn.sh> Co-authored-by: Lukas Wirth <lukas@zed.dev>
# Conflicts: # crates/multi_buffer/src/multi_buffer.rs
Co-authored-by: Lukas Wirth <me@lukaswirth.dev> Co-authored-by: MrSubidubi <dev@bahn.sh>
Co-authored-by: Lukas Wirth <me@lukaswirth.dev> Co-authored-by: MrSubidubi <dev@bahn.sh>
Co-authored-by: Lukas Wirth <me@lukaswirth.dev> Co-authored-by: MrSubidubi <dev@bahn.sh>
Deals with #5259 Highlights brackets with different colors based on their depth. Uses existing tree-sitter queries from brackets.scm to find brackets, uses theme's accents to color them. https://github.com/user-attachments/assets/cc5f3aba-22fa-446d-9af7-ba6e772029da 1. Adds `colorize_brackets` language setting that allows, per language or globally for all languages, to configure whether Zed should color the brackets for a particular language. Disabled for all languages by default. 2. Any given language can opt-out a certain bracket pair by amending the brackets.scm like `("\"" @OPEN "\"" @close) ` -> `(("\"" @OPEN "\"" @close) (#set! rainbow.exclude))` 3. Brackets are using colors from theme accents, which can be overridden as ```jsonc "theme_overrides": { "One Dark": { "accents": ["#ff69b4", "#7fff00", "#ff1493", "#00ffff", "#ff8c00", "#9400d3"] } }, ``` Release Notes: - Added bracket colorization (rainbow brackets) support. Use `colorize_brackets` language setting to enable. --------- Co-authored-by: MrSubidubi <dev@bahn.sh> Co-authored-by: Lukas Wirth <lukas@zed.dev> Co-authored-by: MrSubidubi <finn@zed.dev> Co-authored-by: Lukas Wirth <me@lukaswirth.dev> Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
Deals with zed-industries#5259 Highlights brackets with different colors based on their depth. Uses existing tree-sitter queries from brackets.scm to find brackets, uses theme's accents to color them. https://github.com/user-attachments/assets/cc5f3aba-22fa-446d-9af7-ba6e772029da 1. Adds `colorize_brackets` language setting that allows, per language or globally for all languages, to configure whether Zed should color the brackets for a particular language. Disabled for all languages by default. 2. Any given language can opt-out a certain bracket pair by amending the brackets.scm like `("\"" @OPEN "\"" @close) ` -> `(("\"" @OPEN "\"" @close) (#set! rainbow.exclude))` 3. Brackets are using colors from theme accents, which can be overridden as ```jsonc "theme_overrides": { "One Dark": { "accents": ["#ff69b4", "#7fff00", "#ff1493", "#00ffff", "#ff8c00", "#9400d3"] } }, ``` Release Notes: - Added bracket colorization (rainbow brackets) support. Use `colorize_brackets` language setting to enable. --------- Co-authored-by: MrSubidubi <dev@bahn.sh> Co-authored-by: Lukas Wirth <lukas@zed.dev> Co-authored-by: MrSubidubi <finn@zed.dev> Co-authored-by: Lukas Wirth <me@lukaswirth.dev> Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
…es#43644) Closes zed-industries#43621 Follow-up of zed-industries#43172 Release Notes: - (Preview only) Fixed html tags incorrectly colorized
|
Hello everyone, my bad for bringing up a closed issue :-) thank you |
|
No worries about the post per se: any ones with the technical details are totally worth it. Your bad is that you post sends noise with no context at all — which language, which theme, a snippet to repro etc. |
|
I have no idea what "universal" is in this context, as there's a few axes to track things at, and definitely did not plan to apply this word around. In fact, had tried to explain what this support means in one of the first sentences, perhaps, too condensed: but expanded right below:
From here, we can see that there are "theme accents" and it's possible to configure them, there could be multiple. The rest of the text mentions that So, all The rest is not clear from this PR's description, but has a page in the docs: https://zed.dev/docs/extensions/languages?highlight=brackets.scm#bracket-matching I've found it by opening the docs page and searching for In short, those brackets/highlights/outline/etc.scm files are collections tree-sitter queries on a parcitular topic, which Zed can query without knowing any particular details about the language. Each language is backed up by some of these files, either provided by Zed for some "core" languages like Rust, or via extensions — if any extension does not support bracket queries, it does not include If I quickly check some of the examples' extensions:
and I tend to agree that plain html does not have any syntax brackets? VSCode seems to agree with my confusion:
yet presumably tree-sitter parser library underneath returns some funny bracket ranges that Zed does not normalize normally. |
|
Regarding the bash example, I've checked it a bit more in detail, and seems that its tree-sitter parser itself starts to fail quite badly on brackets misplace: fallbacks.movYou can see that entire chunks of the file stop being highlighted at some, quite log, bracket threshold. The parser is what answers all queries about the language, and tries to make sense of the code, so here's sometimes a fine line between a bad parser and a bad code. Here, it's sort of both: I would expect the parser to recover from yet another bracket pair and continue checking the code better, but it does not happen and it starts to match random bracket pairs at start and end, considering what's between some form of an invalid bash expression. Yet, the bash code with that many brackets is not valid too? One way or another, Zed cannot fix it in its code, and https://github.com/tree-sitter/tree-sitter-bash has to get a fix, or another tree-sitter parser should be used for the language. |
|
Thanks for your quick check and reply. As I understand from your explanation, the new feature will only work if each language properly supports and implements the required Thanks again for your time and the detailed clarification! 🌸 |
… language (zed-industries#43947) Follow-up of zed-industries#43172 Release Notes: - Fixed bracket colorization in file-less files with a proper language








Deals with #5259
Highlights brackets with different colors based on their depth.
Uses existing tree-sitter queries from brackets.scm to find brackets, uses theme's accents to color them.
rainbows.mov
colorize_bracketslanguage setting that allows, per language or globally for all languages, to configure whether Zed should color the brackets for a particular language.Disabled for all languages by default.
Any given language can opt-out a certain bracket pair by amending the brackets.scm like
("\"" @open "\"" @close)->(("\"" @open "\"" @close) (#set! rainbow.exclude))Brackets are using colors from theme accents, which can be overridden as
Release Notes:
colorize_bracketslanguage setting to enable.