feat(coc): auto-register the language server with coc.nvim
coc users had to hand-maintain a coc-settings.json `languageserver.nuwiki`
entry, which didn't track g:nuwiki_wikis / g:vimwiki_list / the global
shorthand and meant editing JSON per wiki. nuwiki now registers itself
programmatically: on the first .wiki buffer it calls
coc#config('languageserver.nuwiki', {…}) with the s:settings() payload
(same config the vim-lsp path sends). coc reacts to the languageserver
config change (onDidChangeConfiguration → registerClientsByConfig) and
starts the server for the open buffer.
Details:
- Reliable coc detection via :CocConfig (exists('*coc#config') can't be
trusted — it doesn't trigger autoload in Vim 9.2). The coc#config call
is wrapped in try/catch and autoloads coc.vim itself; falls back to the
printed snippet only if coc genuinely isn't there.
- Deferred to User CocNvimInit when coc's node service isn't up yet.
- Opt out with g:nuwiki_no_coc_register (then we just print the snippet).
Dogfooded in start-vim-coc.sh: dropped the manual coc-settings.json
languageserver block; the harness now relies on auto-registration from
g:nuwiki_* (real-user flow). New harness test-coc-register-vim (7 checks,
stubbed coc#config) asserts the injected payload incl. the folded global
shorthand; wired into CI. README coc section rewritten (zero-config).
Rust 573 passed, clippy clean, all harnesses green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
" development/tests/test-coc-register-vim.vim — programmatic coc.nvim
|
||||
" registration. Relies on a stub autoload/coc.vim (created by the wrapper) that
|
||||
" records coc#config calls into g:_recorded. Drives nuwiki#lsp#start()'s coc
|
||||
" branch and asserts the exact languageserver config nuwiki injects (command,
|
||||
" filetypes, and the s:settings() payload with the global shorthand folded in).
|
||||
" Writes PASS/FAIL to $NUWIKI_COC_OUT.
|
||||
|
||||
let s:out = []
|
||||
function! s:check(desc, cond) abort
|
||||
call add(s:out, (a:cond ? 'PASS ' : 'FAIL ') . a:desc)
|
||||
endfunction
|
||||
|
||||
" Pretend coc's node service is already up so registration runs synchronously.
|
||||
let g:coc_service_initialized = 1
|
||||
let g:_recorded = {}
|
||||
|
||||
" Make sure the vim-lsp branch is NOT taken.
|
||||
if exists('g:lsp_loaded') | unlet g:lsp_loaded | endif
|
||||
|
||||
" A readable, executable 'binary' so nuwiki#lsp#start() gets past its check.
|
||||
let g:nuwiki_binary_path = executable('true') ? exepath('true') : '/usr/bin/true'
|
||||
|
||||
" Config: single-wiki shorthand + a global display setting that must fold into
|
||||
" the wiki the server sees (the global shorthand).
|
||||
let g:nuwiki_wiki_root = '/tmp/realwiki'
|
||||
let g:nuwiki_toc_header_level = 2
|
||||
|
||||
call nuwiki#lsp#start()
|
||||
|
||||
let s:r = get(g:, '_recorded', {})
|
||||
call s:check('coc#config was called', !empty(s:r))
|
||||
call s:check('section is languageserver.nuwiki', get(s:r, 'section', '') ==# 'languageserver.nuwiki')
|
||||
let s:v = get(s:r, 'value', {})
|
||||
call s:check('command is the binary', get(s:v, 'command', '') ==# g:nuwiki_binary_path)
|
||||
call s:check('filetypes = [vimwiki]', get(s:v, 'filetypes', []) == ['vimwiki'])
|
||||
let s:io = get(s:v, 'initializationOptions', {})
|
||||
call s:check('initOpts has wiki_root', get(s:io, 'wiki_root', '') ==# '/tmp/realwiki')
|
||||
call s:check('global toc_header_level folded into payload', get(s:io, 'toc_header_level', 0) == 2)
|
||||
call s:check('settings.nuwiki mirrors initOpts', get(get(s:v, 'settings', {}), 'nuwiki', {}) ==# s:io)
|
||||
|
||||
call writefile(s:out, $NUWIKI_COC_OUT)
|
||||
qa!
|
||||
Reference in New Issue
Block a user