Colour is messed up/lost after formatting
wutianjun5858 opened this issue · 5 comments
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.
Editing in general seems to confuse rainbow
, not just formatting. It's particularly easy to trigger mismatches in haskell:
We can also sometimes get typescript to screw up:
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.
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.
Same for me in LaTeX