rainbow icon indicating copy to clipboard operation
rainbow copied to clipboard

No colouring in Neovim

Open sansyrox opened this issue 4 years ago • 9 comments

Describe the bug

I have installed this plugin but I am not getting any highlighting in normal mode. When I select the brackets in visual mode, I am to see the pair colorised brackets, but I am unable to see any highlight in normal/insert mode

To Reproduce

I have just installed it and enabled it in plug config. I am getting no errors. How can I debug further ?

Expected behavior

The syntax highlighting should work?

Screenshots

Provide a screenshot to describe what you got. Screenshot 2021-06-11 at 5 53 59 PM

Additional context

Are you using some third-party syntax plugins? Add any other context about the problem here. I am using coc.nvim and tree sitter for highlighting

and I am using this theme: https://github.com/haishanh/night-owl.vim

sansyrox avatar Jun 11 '21 12:06 sansyrox

Can confirm. Doesn't work with neovim 0.5 and native LSP too, sadly.

emseidov avatar Aug 28 '21 20:08 emseidov

Just found out by playing around this plugin now conflicts with TreeSitter's highlight function. To verify, run :TSBufDisable highlight and you get all our shiny parens coloring back... at the price of TS's highlight of semantic parts of the code.

I'll see if TS has an issue about this conflict and whether they can solve it since, in the balance between highlighted parnes and TS, I know what I prefer better. (Also, and not judging, just commenting, Rainbow seems to have been abandoned...)

OmanF avatar Sep 23 '21 12:09 OmanF

The response I got from TS team: https://github.com/nvim-treesitter/nvim-treesitter/issues/1855

Using the suggested plugin (after configuring up to 7 colors in the plugin's config section) works like magic, although, as the commenter says, with a slight hit to performance while TS is parsing the file. Once TS parsed the file fully, the performance hit is slim-to-none.

I suggest closing this issue as a solution is provided by TS team.

OmanF avatar Sep 23 '21 12:09 OmanF

Just for completeness: aside from mapping TSPunctBracket to nonexisting group as mentioned by TS team, you can map captures also (and the result is exactly the same):

highlight = {
	enable = true,
	custom_captures = {
		["punctuation.bracket"] = "",
		["constructor"]         = "",
	},
},

You can get capture group under cursor using :TSHighlightCapturesUnderCursor command from nvim-treesitter/playground plugin Although I am not sure if there's an option to configure captures for specific languages and thus it may be either incomplete with just punctuation.bracket (e.g. Lua and {}) or conflicting if you add more.

EDIT: Seems like you can unmap elements not only in initial configuration, but anytime (with vim.treesitter.highlighter.hl_map['constructor'] = ''), just reattach (i.e. toggle on and off) highlighting once again. This potentially can be used to make a workaround.

Widowan avatar Sep 23 '21 22:09 Widowan

Okay, I'm dumb and it is actually way easier to do with remapping highlight and also allows language-specific modifications

vim.cmd[[augroup rainbow]]
vim.cmd[[	au BufEnter *     hi      TSPunctBracket NONE]]
vim.cmd[[	au BufEnter *     hi link TSPunctBracket nonexistenthl]]
vim.cmd[[	au BufEnter *.lua hi      TSConstructor  NONE]]
vim.cmd[[	au BufEnter *.lua hi link TSConstructor  nonexistenthl]]
vim.cmd[[augroup END]]

Widowan avatar Sep 24 '21 00:09 Widowan

Cool! Will need to compare using nvim-ts-rainbow with rainbow with the mapping and see which is faster/nicer. Thanks for the mapping!

It's so great having options, and both working great!

OmanF avatar Sep 24 '21 05:09 OmanF

rainbow was something that Just Worked(tm) and now, with recent update of TS (I suspect that is the cause, I haven't updated my plugins in a loong time) it broke and I'm struggling with task as simple as highlighting brackets ever since... Those mappings work fine, but not perfect; and nvim-ts-rainbow isn't perfect either (see it's #68 for example).

*Sigh*

Widowan avatar Sep 24 '21 07:09 Widowan

On top of treesitter btw, if you're using a LSP server/client with support for Semantic Tokens, highlighting from this plugin can also be overridden by other groups.

For example, I'm using coc.nvim, treesitter and gruvbox-material (supports both coc.nvim and treesitter). In a Dockerfile (dockerfile-language-server-nodejs), colour of brackets after CMD is overridden by CocSem_parameter/TSParameter cos yeah, technically everything after the space is CMD's parameter.

with semantic tokens image without semantic tokens (or :highlight! link TSParameter NONE) image

So the thing about parenthesis highlighting is, I don't think I even want it to be syntax-wise correct sometimes. Something straightforward like this repo is exactly what I actually need.

Another problem about relying on treesitter to highlight parentheses is that, you don't get colour at all if it's not supported by treesitter. Not to mention there are still quite a number of languages missing from nvim-ts-rainbow itself.

Frederick888 avatar Dec 14 '21 10:12 Frederick888

For new people coming across this, you now have to remap the bracket group by

vim.api.nvim_set_hl(0, "@punctuation.bracket", { link = "" })

since treesitter no longer reads custom_captures

gldanoob avatar Dec 07 '22 22:12 gldanoob