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

Colour is messed up/lost after formatting

Open wutianjun5858 opened this issue 3 years ago • 5 comments

Describe the bug c code when use clang-format, then rainbow become gray

Steps to reproduce use clang-format, rainbow->gray

Expected behavior rainbow do not change

Screenshots before clang-format image

after clang-format image

wutianjun5858 avatar Apr 30 '22 12:04 wutianjun5858

This actually isn't only C code, it gets confused when formatting other code and even messes up highlighting beyond parens too, like Fennel: Before :!fnlfmt --fix %: image

After format: image

diktomat avatar Aug 26 '22 08:08 diktomat

When I manually run :TSDisable rainbow | TSEnable rainbow, it is fixed again. I use this formatter, which exposes event User FormatterPost.

So naturally:

augroup FormatGroup
	autocmd!
	autocmd BufWritePost *.java,*.ts,*.lua,*.py FormatWrite
	autocmd User FormatterPost TSDisable rainbow | TSEnable rainbow
augroup end

should solve the problem. However, this doesn't work on java. Therefore I added my current setup to further investigate. But no luck so far. Maybe someone here is smarter than I am?

Edit:

this solves it for my setup:

augroup FormatGroup
	autocmd!
	autocmd BufWritePost *.java,*.ts,*.lua,*.py FormatWrite
	autocmd FocusGained * TSDisable rainbow | TSEnable rainbow
augroup end

Edit 2: only partially. It still happens, then I quickly change Workspace of my window manager somewhere else and back again. I repeat that until formatting and rainbow braces are displayed correctly. Still not really elegant.

mrdgo avatar Oct 24 '22 08:10 mrdgo

Editing in general seems to confuse rainbow, not just formatting. It's particularly easy to trigger mismatches in haskell:

haskell

We can also sometimes get typescript to screw up:

ts

Interestingly, the behavior alters between TSDisable rainbow | TSEnable rainbow cycles. Matching errors may appear in different places for the same action, and annecdotally, cycling off/on several times in a given file actually seems to clear the issue up. This observation leads to a hack like the following:

autocmd BufNewFile,BufReadPost * TSDisable rainbow | TSEnable rainbow | TSDisable rainbow | TSEnable rainbow | TSDisable rainbow | TSEnable rainbow

I also cycle after every write in case the above isn't enough:

autocmd BufWritePost * TSDisable rainbow | TSEnable rainbow

These both seem to be quick enough that I don't notice, and while they do nothing to illuminate the underlying cause of the issue, they do seem to do a pretty good job of patching it over.

thisisrandy avatar Nov 10 '22 20:11 thisisrandy

The same in Rust as well. I think it's very easy to trigger this bug. For example, I delete a left bracket and retype it and color will mass up.

MrZLeo avatar Nov 23 '22 12:11 MrZLeo

Same for me in LaTeX

WhiteBlackGoose avatar Dec 08 '22 16:12 WhiteBlackGoose