nvim-ts-rainbow2
nvim-ts-rainbow2 copied to clipboard
Bracket coloring inconsistent
Describe the bug
I've noticed that some highlighting is inconsistent: Sometimes a bracket gets highlighted, sometimes it doesn't, sometimes the order of colors is not what is expected. So far I've tested this on TypeScript (+ TSReact) and Rust files.
(also it seems the magenta color is actually more greenish but that's out of scope for this problem) Steps to reproduce
Steps to reproduce the behavior.
I've defined some custom colors:
vim.api.nvim_set_hl(0, "TSRainbowYellow", { fg = "#FFD700" })
vim.api.nvim_set_hl(0, "TSRainbowMagenta", { fg = "#DA70D6" })
vim.api.nvim_set_hl(0, "TSRainbowBlue", { fg = "#87CEFA" })
and then set the plugin up like so:
local opts = {
rainbow = {
enable = true,
strategy = require("ts-rainbow").strategy.global,
hlgroups = {
"TSRainbowYellow",
"TSRainbowMagenta",
"TSRainbowBlue",
},
query = {
"rainbow-parens",
tsx = "rainbow-tags",
},
},
}
require("nvim-treesitter.configs").setup(opts)
Expected behavior All brackets shoudlbe highlighted, and cycle through the defined colors yellow -> magenta -> blue -> yellow etc.
Screenshots
Rust
TypeScript
The Rust snippet looks fine on my machine and I don't see what is supposed to be the problem in your screenshot (except for the colours being different).
The Typescript query was missing some patterns, I have added them now. I have no idea why your colours are off like that. What do you see when you execute :highlight TSRainbowYellow
?
@HiPhish regarding the Rust screenshot: on my machine it seems like the colors don't get cycled correctly, e.g. on the third line, at the match statement, I would expect the {..}
to be TSRainbowMagenta
, but they are uncolored.
Regarding the off color, it seems to be an issue with the way I've set up TSRainbowMagenta
. :highlight TSRainbowMagenta
prints out:
TSRainbowMagenta xxx cleared
I assume that the plugin just falls back on a default color, but this also seems to stop the color cycling.
EDIT: I updated the TSRainbowBlue color to #87CEEB
and after double checking, the output for TSRainbowBlue
also does not seem to match:
TSRainbowBlue xxx ctermfg=12 guifg=#458588
I also found the tsx files are missing some highlights for components with children. I showcased it here: https://github.com/HiPhish/nvim-ts-rainbow2/compare/master...benediktms:nvim-ts-rainbow2:showcase-missing-brackets-highlights?expand=1
I guess you mean to the { ... }
in React? I have added it now, can you please test?
As for the original issue, is the way the screenshot above looks what you expect?
I've tested this again with the same colors I mentioned above, but the bracket highlight still does not seem to like my colors:
Where and when are you defining your highlight groups? What happens if you set your highlight groups manually while the buffer is open (e.g. :hi TSRainbowRed guifg=#ff0000
or whatever colour you want)
Colour schemes usually clear all highlight groups, so if you define your own highlight groups before Vim set the colour scheme your settings will be wiped out.
ahh thanks for pointing that out! I didn't even take that into consideration. It works now, for the most part, however the color rotation still sometimes does not work correctly, see screenshow below of a .tsx file:
The type declaration File[]
is missing the brackete highlights, as well as brackets for the for (...)
loop
This plugin is now deprecated because of upcoming changes to nvim-treesitter. The new rainbow plugin is here: rainbow-delimiters.nvim (GitHub mirror). Please file an issue over there if the problem still persists.