Implement bracket coloring by depth #21875
Draft
+225
−90
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.
Implement bracket coloring by depth.
Closes #5259.
Hi! 👋 This is my first PR.
I just hit a wall and need some feedback.
(I'm willing to pair!)
Approach taken
In the Tree Sitter highlighting rules file
highlights.scm
, add two captures:punctuation.bracket.open
punctuation.bracket.close
So we can track depth with the existing highlighting pass (no additional tree traversals).
This is backward-compatible with extensions, as
punctuation.bracket
is only used for highlighting, andpunctuation.bracket.[open,close]
are both highlighted by thepunctuation.bracket
style as a fallback.The PR code is language-agnostic and bracket coloring doesn't work till the language's
highlights.scm
file is updated with bothopen
andclose
definitions, this way, extension authors can choose what symbols should be colored by depth for the respective language.Note about
brackets.scm
(click me).Problems
I'm checking Tree Sitter captures in the iteration done in
BufferChunks
, but it seems like the highlights query doesn't walk the syntax from the very start.As a result, when I scroll down into nested scopes, I can't keep track of the context in the lines above, which makes calculating the depth impossible.
Am I missing something?
TODO:
punctuation.bracket.[open,close]
for extensionshighlights.scm
of remaining languages in the repopunctuation.bracket
or text color?Open questions:
(
match colors with the next}
or]
?Release Notes: