Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No colouring in Neovim #163

Open
sansyrox opened this issue Jun 11, 2021 · 9 comments
Open

No colouring in Neovim #163

sansyrox opened this issue Jun 11, 2021 · 9 comments

Comments

@sansyrox
Copy link

sansyrox commented Jun 11, 2021

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

@Lambdaphile
Copy link

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

@OmanF
Copy link

OmanF commented Sep 23, 2021

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
Copy link

OmanF commented Sep 23, 2021

The response I got from TS team: nvim-treesitter/nvim-treesitter#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.

@Widowan
Copy link

Widowan commented Sep 23, 2021

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
Copy link

Widowan commented Sep 24, 2021

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

@OmanF
Copy link

OmanF commented Sep 24, 2021

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!

@Widowan
Copy link

Widowan commented Sep 24, 2021

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*

@Frederick888
Copy link

Frederick888 commented Dec 14, 2021

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.

ericonr added a commit to ericonr/dotfiles that referenced this issue Jun 30, 2022
Haven't enabled almost anything explicitly yet because of [1]; I like
rainbow. Should be simple to fix, just requires some config changes.

Have definitely enabled TS for .tex files though, since the native
syntax highlighting is way too slow.

[1] luochen1990/rainbow#163
@gldanoob
Copy link

gldanoob commented Dec 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants