nvim-ts-rainbow2 icon indicating copy to clipboard operation
nvim-ts-rainbow2 copied to clipboard

Bracket coloring inconsistent

Open benediktms opened this issue 1 year ago • 8 comments

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 image

TypeScript image

benediktms avatar May 27 '23 10:05 benediktms

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

Screenshot_20230527_230617

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 avatar May 27 '23 21:05 HiPhish

@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

benediktms avatar May 28 '23 08:05 benediktms

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

benediktms avatar May 31 '23 15:05 benediktms

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?

HiPhish avatar Jun 04 '23 21:06 HiPhish

I've tested this again with the same colors I mentioned above, but the bracket highlight still does not seem to like my colors: image

benediktms avatar Jun 15 '23 08:06 benediktms

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.

HiPhish avatar Jun 21 '23 19:06 HiPhish

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:

Screenshot 2023-06-23 at 10 21 20

The type declaration File[] is missing the brackete highlights, as well as brackets for the for (...) loop

benediktms avatar Jun 23 '23 09:06 benediktms

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.

HiPhish avatar Jul 03 '23 18:07 HiPhish