Skip to content

Support bracket colorization (rainbow brackets)#43172

Merged
SomeoneToIgnore merged 84 commits intomainfrom
kb/rainbow-brackets
Nov 20, 2025
Merged

Support bracket colorization (rainbow brackets)#43172
SomeoneToIgnore merged 84 commits intomainfrom
kb/rainbow-brackets

Conversation

@SomeoneToIgnore
Copy link
Contributor

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
  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.

  1. Any given language can opt-out a certain bracket pair by amending the brackets.scm like ("\"" @open "\"" @close) -> (("\"" @open "\"" @close) (#set! rainbow.exclude))

  2. Brackets are using colors from theme accents, which can be overridden as

"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.

SomeoneToIgnore and others added 30 commits October 3, 2025 15:13
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: Lukas Wirth <lukas@zed.dev>

# Conflicts:
#	crates/editor/src/highlight_matching_bracket.rs
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>
@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) November 20, 2025 19:36
@SomeoneToIgnore SomeoneToIgnore merged commit 7e341bc into main Nov 20, 2025
23 checks passed
@SomeoneToIgnore SomeoneToIgnore deleted the kb/rainbow-brackets branch November 20, 2025 19:47
mikayla-maki pushed a commit that referenced this pull request Nov 20, 2025
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>
0x2CA added a commit to EmmyLuaLs/Zed-EmmyLua that referenced this pull request Nov 24, 2025
SomeoneToIgnore added a commit that referenced this pull request Nov 27, 2025
Closes #43621
Follow-up of #43172

Release Notes:

- (Preview only) Fixed html tags incorrectly colorized
github-actions bot pushed a commit that referenced this pull request Nov 27, 2025
Closes #43621
Follow-up of #43172

Release Notes:

- (Preview only) Fixed html tags incorrectly colorized
zed-zippy bot added a commit that referenced this pull request Nov 27, 2025
…rry-pick to preview) (#43645)

Cherry-pick of #43644 to preview

----
Closes #43621
Follow-up of #43172

Release Notes:

- (Preview only) Fixed html tags incorrectly colorized

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
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>
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…es#43644)

Closes zed-industries#43621
Follow-up of zed-industries#43172

Release Notes:

- (Preview only) Fixed html tags incorrectly colorized
SomeoneToIgnore added a commit that referenced this pull request Dec 1, 2025
… language (#43947)

Follow-up of #43172

Release Notes:

- Fixed bracket colorization in file-less files with a proper language
github-actions bot pushed a commit that referenced this pull request Dec 1, 2025
… language (#43947)

Follow-up of #43172

Release Notes:

- Fixed bracket colorization in file-less files with a proper language
zed-zippy bot added a commit that referenced this pull request Dec 1, 2025
… language (#43947) (cherry-pick to preview) (#43948)

Cherry-pick of #43947 to preview

----
Follow-up of #43172

Release Notes:

- Fixed bracket colorization in file-less files with a proper language

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
@vhp1360
Copy link

vhp1360 commented Dec 6, 2025

Hello everyone, my bad for bringing up a closed issue :-)
If you're open to feedback,this feature only works for square brackets at this time,if you dont mind, it might be cooler if works for parentheses and curly brackets too.

thank you

@SomeoneToIgnore
Copy link
Contributor Author

SomeoneToIgnore commented Dec 6, 2025

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.

@vhp1360
Copy link

vhp1360 commented Dec 6, 2025

thanks for reply and sorry for less info because the first message in this topic kinda suggested this featureis universal and I know some file type might not be this feature.
but for more information, I checked in some files type
as I checked the curly braces not colorized in plain text,file with unknown type, yaml, jinja sample,json file
image
actually in above image, open parentheses dont close automatically and that happened for all bracket types if between double quotes.
in html file type:
image
in bash type
image
in conf file like nginx.conf
image
in Dockerfile
image

@SomeoneToIgnore
Copy link
Contributor Author

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:
image

but expanded right below:

image

From here, we can see that there are "theme accents" and it's possible to configure them, there could be multiple.
From the screenshots it seems that there are no issue with the color order and if there would be, there is a text on how to adjust that per theme.

The rest of the text mentions that brackets.scm are in play, and bracket pairs are considered (that is also displayed in that tree-sitter query with (#set! rainbow.exclude) bit).

So, all ((((((((((((((( things like the last visible line of your Dockerfile example won't be highlighted because those are not bracket pairs.

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 brackets.scm from this PR's description.

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 brackets.scm file into its bundle.
If that happens, Zed cannot colorize the brackets; neither can Zed colorize the bracket pairs that are not mentioned in brackets.scm.

If I quickly check some of the examples' extensions:

("<" @open "/>" @close)
("</" @open ">" @close)
("<" @open ">" @close)
(("\"" @open "\"" @close) (#set! rainbow.exclude))
((element (start_tag) @open (end_tag) @close) (#set! newline.only) (#set! rainbow.exclude))

and I tend to agree that plain html does not have any syntax brackets?
What are all those {} [] and () pairs mean in terms of html language?

VSCode seems to agree with my confusion:
image

  • bash (and css when I looked at it comparing to VSCode) examples are the most interesting ones, those seem like a bug in Zed, as the bracket queries are similar to what Rust has:

https://github.com/zed-industries/zed/blob/d72746773faf458452ee393cf3ec01a164f98b37/crates/languages/src/bash/brackets.scm#L1-L13

yet presumably tree-sitter parser library underneath returns some funny bracket ranges that Zed does not normalize normally.

@SomeoneToIgnore
Copy link
Contributor Author

SomeoneToIgnore commented Dec 6, 2025

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.mov

You 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.

@vhp1360
Copy link

vhp1360 commented Dec 6, 2025

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 brackets.scm queries. Also, if brackets (like the unclosed parentheses in some of my screenshots) aren't highlighted, it's likely due to missing or incomplete support in the language extension.

Thanks again for your time and the detailed clarification! 🌸

someone13574 pushed a commit to someone13574/zed that referenced this pull request Dec 16, 2025
… language (zed-industries#43947)

Follow-up of zed-industries#43172

Release Notes:

- Fixed bracket colorization in file-less files with a proper language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants