fix(vim): gate Neovim TS-style highlight groups + correct bin path lookup
CI / cargo fmt --check (push) Successful in 28s
CI / cargo clippy (push) Successful in 1m20s
CI / cargo test (push) Successful in 1m16s

Plain Vim spat a wall of `W18: Invalid character in group name` on
every buffer load because `syntax/vimwiki.vim` declared the
LSP-token highlight defaults with Tree-sitter-style names
(`@vimwikiHeading.level1`, `@vimwikiBold`, …). Those work on Neovim
but Vim rejects `@` and `.` in group names.

- `syntax/vimwiki.vim` now guards the `@vimwiki*` block with
  `has('nvim')`. The static regex fallback below it (which uses
  Vim-compatible `nuwiki*` group names) keeps highlighting working
  on plain Vim.

While reproducing, also noticed `autoload/nuwiki/lsp.vim`'s
`s:bin_path` reported the binary at `/home/gfranco/bin/nuwiki-ls`
(only two dirs under `$HOME`) instead of
`/home/gfranco/git-repositories/nuwiki/bin/nuwiki-ls`. Cause:
`expand('<sfile>:p')` inside a function resolves to the *calling*
script at invocation time, not this autoload file. Captured the
plugin root via `<sfile>` at script-load time into a new
`s:plugin_root` and used it in `bin_path()`.

Verified with `vim -u .vimrc index.wiki`:
- `:messages` is empty of W18 warnings.
- The "binary not found" path (when no built binary exists) now
  prints the correct repo-relative path.

Total 377 Rust tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 01:04:23 +00:00
parent d58a34a2d7
commit f1bf70d448
2 changed files with 46 additions and 35 deletions
+6 -2
View File
@@ -5,6 +5,11 @@
" 2. coc.nvim
" 3. Print an error if neither is available.
" Resolve the plugin root at script-load time. `<sfile>` inside a
" function later returns the *calling* script's path, not this file's
" — capturing it here is the reliable way.
let s:plugin_root = fnamemodify(resolve(expand('<sfile>:p')), ':h:h:h')
let s:started = 0
function! nuwiki#lsp#start() abort
@@ -60,9 +65,8 @@ function! s:bin_path() abort
if exists('g:nuwiki_binary_path') && filereadable(g:nuwiki_binary_path)
return g:nuwiki_binary_path
endif
let l:plugin_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h:h:h')
let l:suffix = has('win32') ? '.exe' : ''
return l:plugin_dir . '/bin/nuwiki-ls' . l:suffix
return s:plugin_root . '/bin/nuwiki-ls' . l:suffix
endfunction
function! s:settings() abort
+9 -2
View File
@@ -1,4 +1,4 @@
" syntax/nuwiki.vim — default highlight groups for nuwiki.
" syntax/vimwiki.vim — default highlight groups for nuwiki.
"
" Two responsibilities:
" 1. Default `@vimwiki*` highlight groups for the LSP semantic tokens
@@ -6,13 +6,19 @@
" cycle after server startup already has colours.
" 2. A small regex-based fallback so static highlighting works on
" buffers where the LSP isn't running yet.
"
" The `@group.modifier` group names are Neovim's Tree-sitter convention
" — plain Vim rejects `@` and `.` with W18, so the LSP-token defaults
" are gated behind `has('nvim')`. The static fallback below works
" everywhere.
if exists('b:current_syntax')
finish
endif
" ===== Semantic-token defaults (Neovim's TS-style @group names) =====
" ===== Semantic-token defaults (Neovim only — uses TS-style @group names) =====
if has('nvim')
" Headings — level modifiers map to progressively softer accents.
highlight default link @vimwikiHeading Title
highlight default link @vimwikiHeading.level1 Title
@@ -48,6 +54,7 @@ highlight default link @vimwikiKeyword Todo
highlight default link @vimwikiColor Constant
highlight default link @vimwikiComment Comment
highlight default link @vimwikiDefinitionTerm Statement
endif
" ===== Static fallback (no LSP required) =====