ap / vim-css-color

Preview colours in source code while editing
http://www.vim.org/scripts/script.php?script_id=5056
MIT License
1.77k stars 78 forks source link

Error with files with no highlightable targets in Vim9 #174

Closed Aryailia closed 2 years ago

Aryailia commented 2 years ago

When opening HTML or markdown files without anything that vim-css-color would normally color, I get the following error at startup:

Error detected while processing BufNewFile Autocommands for "*.md"..FileType Autocommands for
 "*"..Syntax Autocommands for "*"..function <SNR>4_SynSet[25]..script /usr/share/vim/vim90/sy
ntax/markdown.vim[15]../home/user/.config/vim/package/vim-css-color/after/syntax/html.vim[2]..
function css_color#init[10]..css_color#enable[15]..CursorMoved Autocommands for "<buffer=1>".
.function <SNR>42_parse_screen[5]..<SNR>42_create_syn_match[20]..BufNewFile Autocommands for
"*.md"..FileType Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>4_SynSet[25
]..script /usr/share/vim/vim90/syntax/markdown.vim[15]../home/user/.config/vim/package/vim-css
-color/after/syntax/html.vim[2]..function css_color#init[10]..css_color#enable[15]..CursorMov
ed Autocommands for "<buffer=1>"..function <SNR>42_parse_screen[5]..<SNR>42_create_syn_match:

line   20:
E605: Exception not caught: css_color: create_syn_match invoked on bad match data

This doesn't seem to affect anything other than displaying an error message at vim startup. This happens on files with content and with new files, the problem seeming to be the lack of a highlightable color. This error also occurs with a fresh .vimrc, VimPlug, set nocompatible, filetype plugin indent on. This seems to be an issue that has only popped up as of vim9 (vim-9.0.0135). Running the my full vim setup in a docker container that has vim8 seems to not run into this issue.

As soon as I save something like <div color="#AA0000"> and reopen the file, vim no longer displays the error.

I narrowed this down to the as being caused by the commit d70f5fb0b57ad85309347607b4f15f3371361cf4 . Reverting the line as displayed below does indeed resolve it, and the highlighting of vim-color-css seems to not be affected, at least at first glance.

+   call substitute( join( getline('w0','w$'), "\n" ), b:css_color_pat, '\=s:create_syn_match()', 'g' )
-   call filter( range( line('w0'), line('w$') ), 'substitute( strpart( getline(v:val), col([v:val, left]), width ), b:css_color_pat, ''\=s:create_syn_match()'', ''g'' )' )
ap commented 2 years ago

Thank you for reporting this.

the highlighting of vim-color-css seems to not be affected, at least at first glance.

It will indeed not be affected. Only performance might, in very bloated files.

I’m not sure what’s going on as ⓐ I don’t think I can reproduce the error despite using Vim 9 as my daily driver (but only 9.0.0065; who knows if that’s relevant) and ⓑ there’s quite a bit going on in that line but the error does not obviously seem connected to any of it, and so the change you made does not obviously look like it should fix it.

Does opening an empty HTML/Markdown file throw the error too?

If you are willing to help me narrow this down, can you try this line instead and tell me if that also triggers the error?

call filter( range( line('w0'), line('w$') ), 'substitute( getline(v:val), b:css_color_pat, ''\=s:create_syn_match()'', ''g'' )' )
Aryailia commented 2 years ago

I went about recreating a clean vim config environment to test this issue, and the issues magically disappeared. I deleted my vim directory and checking it out again from my dotfiles repo seems to have fixed it magically. So I guess either I made a mistake the first time around, or an update (though my vim version didn't change), or something tweaking a long the way fixed something.

So uhh... sorry for crying wolf.

ap commented 2 years ago

No worries, happens to all of us. 🙂 Thanks for going to the trouble of trying to reproduce the issue cleanly, even if the outcome was that it just up and disappeared (sort of an inverse of the stages of debugging I guess (“how did that ever not work?”)). I’d rather err on the side of the occasional false positive than an occasional real issue going unreported, even if it means wasting a few minutes.

Jefferson-Faseler commented 1 year ago

I am also having this same issue with markdown files.

I ran your debug line from the comment above in command mode and as a vimscript and got

E120: Using <SID> not in a script context: s:create_syn_match

As a vimscript

:so debug.vim

Error detected while processing /Users/whoami/code/team-utils/debug.vim:
line    1:
E117: Unknown function: s:create_syn_match
Press ENTER or type command to continue

I won't pretend to be a vimscript expert, and I'm pretty swamped to understand loading files today but I can run further debugging if you need.

And to answer your other question about it happening in an empty md file, yes. It still happens. Seems to be just any md filetype. However, it isn't happening on html files like the original issue message.