-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Long go files cause syntax highlighting to think everything is a string #1447
Comments
Oh and FWIW |
The core problem is that "syntax highlighting" in Vim is a series of regular expressions. Because you don't want to re-run that on the entire buffer on every screen update Vim tries to be a bit smarter about what to update. Unfortunately this sometimes fails, and stuff gets highlighted wrong; the large the file is, the greater the chance that this will happen. This is kind of a limitation of Vim's syntax highlighting, and it's not a problem in just vim-go; I've seen it with many filetypes. Usually doing a screen update
I also run it when entering a buffer:
You can also try setting Maybe we can run this automatically after running gofmt? |
Oh cool, that sounds like it's a nice workaround. +1 to automatically doing that after |
PR here: #1582 |
This should ensure that it breaks less often. The downside is that it's a bit slower, but it still seems plenty fast enough on my system even with large files. Fixes #1447
Behavior
Sometimes I'll be editing a somewhat long (1000 lines +) go file, and everything is working great until I go to save the file. On a
:w
the entirety of what I can see in a file will change to be colored as if it's a string (yellow in my colorscheme).If I scroll up in the file, eventually I'll hit some section that isn't colored like a string, and then if I scroll back to where I was everything is colored correctly. I can even use this trick to make the same part of a file colored both correctly and not correctly in two different vim windows.
Here's a screenshot of that happening:
I have vim set to run
gofmt
on write, so my uneducated guess as to what's happening is that vim is saving the file,gofmt
does its thing, and then vim loads in less of the file than it had saved before. The syntax highlighting starts parsing from the start of what vim has loaded, and if it starts in the middle of a string everything gets confused.Running
:e
sometimes fixes the problem (but usually doesn't), and changing some text and running:w
sometimes fixes the problem (but usually doesn't).Steps to reproduce:
Here's a file that I believe shows this problem. There's a very long string in the beginning of the file, and thus by the end of the file the beginning of whatever buffer vim has loaded will be in the string. For all I know though, this could be a related problem and not exactly what I'm experiencing.
https://gist.github.com/dgonyeo/31f1c3076328dbb6719337d3ab5cf5ac
Opening that file with vim, and pressing
G
to go to the bottom, note that the main function is not colored correctly.I reproduced this in a fedora docker container (so no preexisting configuration), installing git, go, and vim and installing vim-go with the following command:
There was no
.vimrc
or other plugins.Configuration
Here's a wall of text with information about the environment I reproduced this in:
For what it's worth, I have the same problem in neovim.
The text was updated successfully, but these errors were encountered: