Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Colour is messed up/lost after formatting #112

Open
wutianjun5858 opened this issue Apr 30, 2022 · 5 comments
Open

Colour is messed up/lost after formatting #112

wutianjun5858 opened this issue Apr 30, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@wutianjun5858
Copy link

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

@d12bb
Copy link

d12bb commented Aug 26, 2022

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

@p00f p00f added bug Something isn't working help wanted Extra attention is needed labels Oct 24, 2022
@mrdgo
Copy link

mrdgo commented Oct 24, 2022

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.

@p00f p00f changed the title clang-format then rainbow become gray Colour is messed up/lost after formatting Oct 27, 2022
@p00f p00f pinned this issue Oct 27, 2022
@thisisrandy
Copy link

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.

@MrZLeo
Copy link

MrZLeo commented Nov 23, 2022

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.

@WhiteBlackGoose
Copy link

Same for me in LaTeX

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants