vim icon indicating copy to clipboard operation
vim copied to clipboard

check_colors.vim can incorrectly report "No highlight definition"

Open gdupras opened this issue 5 years ago • 4 comments

Describe the bug check_colors.vim can output "No highlight definition" for groups that actually have a highlight definition. I believe this happens because the script searches for patterns in the color scheme file instead of checking the effects of the file.

To Reproduce

  1. Open the jellybeans color scheme in Vim: jellybeans.vim
  2. :source $VIMRUNTIME/colors/tools/check_colors.vim
  3. check_colors.vim incorrectly outputs "Search: No highlight definition for Search".

Expected behavior check_colors.vim should not output that line since the highlight for Search is actually defined in the file color scheme file:

call s:X("Search","f0a0c0","302028","underline","Magenta","")

So instead of defining the highlight group directly with highlight Search ..., it does so with the help of the s:X function, also in that file:

fun! s:X(group, fg, bg, attr, lcfg, lcbg)
   "...
endfun

Environment:

  • Vim version: 8.2.2543
  • OS: Kubuntu 20.10
  • Terminal: Konsole

Additional context I think check_colors.vim would be more accurate if it used functions such as hlexists, hlID and synIDattr, after sourcing the color scheme file. For example, the output of

hlID("Search")->synIDtrans()->synIDattr('bg', 'gui')

is #302028 , which is correct.

gdupras avatar Feb 24 '21 20:02 gdupras

The idea of the check_colors script initially was, that it should test for a well-defined colorscript, without having to source it initially. That of course works only so much, and for sophisticated color schemes that use functions to define everything, I suppose sourcing the color script would be the only way to make sure it works correctly.

chrisbra avatar Feb 24 '21 21:02 chrisbra

Yes, this was just a script to do some basic checks. Perhaps a much better script can be made and put in the context of the project to improve the colorschemes. Most likely contributions to https://github.com/vim/colorschemes are welcomed.

brammool avatar Feb 26 '21 12:02 brammool

The script check_colors.vim is akin to a simple linting tool—which is a feature. The risk of checking the effects of the color scheme (assuming that it is something even possible to do reliably) rather than its source code is that the checks could pass for color schemes that are a horrible mess. The “trend” we are pushing in https://github.com/vim/colorschemes is towards a homogeneous style and feature set. This applies, of course, only to color schemes that are eligible for inclusion in Vim, and check_colors.vim is meant mostly as a sanity check for such color schemes.

The “No highlight definition” error should be interpreted as the lack of an explicit highlight command (not embedded in a string). In that sense, the errors are technically correct.

That said, it is certainly possible to improve the script and maybe extend its scope. As Bram says, the colorschemes project welcomes feedback and contributions!

lifepillar avatar Feb 27 '21 19:02 lifepillar

Most likely contributions to https://github.com/vim/colorschemes are welcomed.

As Bram says, the colorschemes project welcomes feedback and contributions!

So I guess the issue can be closed since there is a better repo which is dedicated to Vim's color schemes, and to the tools around it.


Unrelated, but there is a bug in the current script. If we press Escape while the report is printed in the pager, 'cpoptions' is not properly restored:

diff --git a/runtime/colors/tools/check_colors.vim b/runtime/colors/tools/check_colors.vim
index b0146cc67..0d8936042 100644
--- a/runtime/colors/tools/check_colors.vim
+++ b/runtime/colors/tools/check_colors.vim
@@ -226,7 +226,13 @@ fu! Result(err)
   endif
 endfu
 
-call Test_check_colors()
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
+try
+  call Test_check_colors()
+catch
+  echohl ErrorMsg
+  echomsg v:exception
+  echohl NONE
+finally
+  let &cpo = s:save_cpo
+  unlet s:save_cpo
+endtry

lacygoill avatar Nov 24 '21 17:11 lacygoill