Closed mcmillion closed 5 years ago
Hello. Thanks for reporting.
I suspect you are viewing a rather long file. Vim has a limit to how many lines it can "remember" to initialize a syntax block and keep highlighting. If it exceeds this limit it usually just drops the highlighting. (I sometimes get this is git commit patches).
There is another open issue that makes me re-evaluate the current setup (especially regarding typescript). Maybe if I find the time I can split the definitions of typescript and javascript, which would significantly reduce the effort to highlight javascript files, and maybe thus fixes this particular misbehavior.
Can you possibly share some more insights into the file you are watching? Is that a large JSON object? How many lines does the file have? Is there anything specific to the data that might cause a syntax issue (e.g. jsx or base64 in data, etc.). As much as you are able/comfortable to disclose, of course, would help.
🙇
So the file is decently long (270ish lines), so that could be part of it, but it does render fine with the styled-components plugin turned off. It's just a vanilla JS file that exports an object. What's weird is I don't remember seeing this issue on any files in my project until a week or so ago. I'm starting to wonder if this is because of a recent neovim update.
Here's another shot of it in another colorscheme. What's weird is that it's only affecting some of the syntax highlighting (e.g. the string values in that screenshot are correct, but the keys are not)
It's also triggering the bracket matching to think that it's not closed, which feels like a hint, but I don't know near enough about how vim/neovim syntax highlighting works to know why.
Just saw this in another file (it's only 100 lines). The syntax highlighting doesn't shift colors when scrolling like the other one does, but the same highlighting weirdness is there on the closing braces.
I'm seeing this as well.
Highlighting breaks following backticks (`), but works intermittently as I scroll through the files.
I don't see the issue when I disable the styled-components
plugin.
I really need to find a solution to this. vim-styled-components
is the only thing left from me finishing my nvim config :/
@mcmillion @lynndylanhurley @fr3fou Can you do me a favor and type :syntax sync fromstart
and see if that changes anything?
What I suspect is happening is that the syntax elements are more than the syncing needs to correctly highlight complex/long files. Setting the syncing to fromstart
means it's caching all the lines in the file, which makes the syntax highlighting take longer but should be more correct.
@fleischie I was experiencing the same issue, :syntax sync fromstart
fixes the issue for me.
For other people, please note there may be performance implications. You can read more about it here: https://vim.fandom.com/wiki/Fix_syntax_highlighting
That worked! Thanks!!
I added this to my .vimrc
and it seems to have fixed the issue:
autocmd BufEnter * :syntax sync fromstart
I personally would advise against putting :syn sync fromstart
in a general location for a general type (because it can slow down vim).
Especially as this plugin is mostly for javascript/typescript files.
So, if anything use autocmd BufEnter *.{js,ts,jsx,tsx} :syntax sync fromstart
(and maybe autocmd BufLeave *.{js,ts,jsx,tsx} :syntax sync clear
(this should reset all syntax sync settings, but beware that this overwrites any additional settings that might have happened, ymmv).
I will add a short description to the README.md outlining this issue and how to circumvent it.
Not sure when this started happening (I've been using this plugin alongside vim-javascript for a while), but in a recent update, this plugin starts to break vanilla JS highlighting when scrolling:
Note that this is in a .js file with just javascript as the filetype. This is with only vim-javascript and vim-styled-components enabled. Doesn't matter if I enable vim-jsx-pretty or not.