Learning a new codebase (Neovim)
As a programmer when I encounter a problem with an opensource programme I feel a little like it is my duty to see if maybe I should (and could) fix it. I am an average software developer and have had some experience altering well known tools such as binutils and gcc so when there is a problem with Neovim why not try and fix it?
The Problem
Soon I will be writing a lot of C# and I don't want to do that without the assistance that is afforded by modern tooling (I am thinking of LSP with Neovim). Unfortunately after I setup omnisharp-roslyn
it makes some obscure complaint:
Error executing vim.schedule lua callback:
...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:344:
Vim(redraw):E5248: Invalid character in group name
stack traceback:
[C]: in function 'nvim_command'
...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:344: in function 'process_response'
...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:269: in function 'handler'
/usr/local/share/nvim/runtime/lua/vim/lsp.lua:1391: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
I also have the clangd
lsp server configured for my Neovim and so I do not think it is related to my specific setup of nvim-lspconfig
.
Summary of my Setup
Base distribution Alpine Linux 3.17.
neovim ef18c9f9b05caf1f39ed32762f53802e378f143b
Step 1
The error message is quite useful but it does not display the character or the name of the group. So, see if I can try and enable logging to write the group name. The source code includes many lines with the following calls to the logging library:
ILOG/ELOG/WLOG
To enable all these lines to write something to ~/.local/state/nvim/log
the source must be compiled with the correct MIN_LOG_LEVEL
this can be achieved by altering CMakeLists.txt
or choosing a Debug build.
make CMAKE_BUILD_TYPE=Debug
Running nvim
from the build directory:
neovim/build/bin/nvim
Should now result in many messages being written to the log... including:
INF 2023-01-04T09:40:25.720 nvim.32411.0 emsg_multiline:723:
Error executing vim.schedule lua callback:
...local/share/nvim/runtime/lua/vim/lsp/semantic_tokens.lua:344: Vim(redraw):E5248: Invalid character in group name
Excellent, now find the ILOG line that writes that to the log:
$ grep -rHn 'E5248: Invalid character' src/
src/nvim/globals.h:1020:EXTERN char e_highlight_group_name_invalid_char[] INIT(= N_("E5248: Invalid character in group name"));
$ grep -rHn e_highlight_group_name_invalid_char src/
src/nvim/highlight_group.c:1867: emsg(_(e_highlight_group_name_invalid_char));
...so the line that causes the error is in src/nvim/highlight_group.c
. It follows that the ILOG line would be somewhere nearby.
Step 2
Add the ILOG line to show the name of the problem token:
} else if (!ASCII_ISALNUM(c) && c != '_' && c != '.' && c != '@') {
// '.' and '@' are allowed characters for use with treesitter capture names.
ILOG("%s CUSTOM ILOG LINE %.*s", e_highlight_group_name_invalid_char, (int)len, name);
msg_source(HL_ATTR(HLF_W));
emsg(_(e_highlight_group_name_invalid_char));
return 0;
Compile the programme and run with a .cs
file to create the problem whilst in a separate terminal dumping the log (and filtering out all the ERR and DBG messages):
$ tail -f .local/state/nvim/log |grep '^INF'
Wao, it looks like OmniSharp is sending @class name
(which contains a space character 0x20):
INF 2023-01-04T09:54:24.706 nvim.861.0 syn_add_group:1867: E5248: Invalid character in group name CUSTOM ILOG LINE @class name
INF 2023-01-04T09:54:24.707 nvim.861.0 syn_add_group:1867: E5248: Invalid character in group name CUSTOM ILOG LINE @static symbol
INF 2023-01-04T09:54:24.707 nvim.861.0 syn_add_group:1867: E5248: Invalid character in group name CUSTOM ILOG LINE @method name
Step 3
What to do about this? Maybe see if it is possible to discover the section of the language server protocol interaction that emits @class name
?