mrjones2014 / nvim-ts-rainbow

Rainbow parentheses for neovim using tree-sitter.
Apache License 2.0
174 stars 4 forks source link

Highlighting not reloading on buffer reload #9

Closed LiadOz closed 1 year ago

LiadOz commented 1 year ago

This is a bug from the original repository https://github.com/p00f/nvim-ts-rainbow/issues/112 This bug happens whenever a buffer is reloaded and it's content changes, this could happen by using a formatter, using git to checkout an open file, or any other actions that modifies an open file from outside of Neovim.

I have submitted 2 fixes for the issue https://github.com/mrjones2014/nvim-ts-rainbow/pull/8 https://github.com/nvim-treesitter/nvim-treesitter/issues/4187 Essentially, when the rainbow plugin reloads, it seems that the tree has not been reparsed, and so the function full update uses the previous tree to create the highlights. The changes to treesitter are needed because the detach function is only called after the first reload. So if a buffer is reloaded more than once then there still may be invalid highlights.

For simplicity, if you want to check my branch without checking out a different treesitter branch you can add

vim.api.nvim_buf_clear_namespace(bufnr, nsid, 0, -1)

to the start of the M.attach function.

mrjones2014 commented 1 year ago

I believe this is fixed by #8

xiantang commented 1 year ago

I believe this is fixed by #8

work like a charm