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:
@@ -72,46 +72,14 @@ ensure_coc() {
|
||||
|
||||
write_coc_settings() {
|
||||
mkdir -p "$DEV_DIR"
|
||||
# Mirror what the vim-lsp client sends (autoload/nuwiki/lsp.vim s:settings()):
|
||||
# both `initializationOptions` (sent on initialize) and `settings.nuwiki`
|
||||
# (served via workspace/configuration). Without these the server falls back
|
||||
# to its own default wiki_root (~/vimwiki) instead of $WIKI_DIR, so it can't
|
||||
# resolve links (e.g. Notes shows as broken) or create-on-follow correctly.
|
||||
# toc_header_level / html_header_numbering are set to non-defaults so the
|
||||
# dev wiki exercises them: :NuwikiTOC writes `== Contents ==` (level 2) and
|
||||
# HTML export numbers headings. coc reads this file verbatim, so these are
|
||||
# the values the server actually receives.
|
||||
# No `languageserver.nuwiki` block here on purpose: this dogfoods nuwiki's
|
||||
# *programmatic* coc registration (autoload/nuwiki/lsp.vim → coc#config). The
|
||||
# plugin registers the server itself from g:nuwiki_* (set in the vimrc),
|
||||
# exactly the "no hand-written coc-settings.json" flow real users get. Only
|
||||
# the jump-command preference (the <CR>-opens-a-tab reproducer) lives here.
|
||||
cat > "$COC_SETTINGS" <<EOF
|
||||
{
|
||||
"coc.preferences.jumpCommand": "$COC_JUMP",
|
||||
"languageserver": {
|
||||
"nuwiki": {
|
||||
"command": "$REPO_ROOT/bin/nuwiki-ls",
|
||||
"filetypes": ["vimwiki"],
|
||||
"initializationOptions": {
|
||||
"wiki_root": "$WIKI_DIR",
|
||||
"file_extension": ".wiki",
|
||||
"syntax": "vimwiki",
|
||||
"log_level": "info",
|
||||
"toc_header_level": 2,
|
||||
"html_header_numbering": 2,
|
||||
"html_header_numbering_sym": " -",
|
||||
"diagnostic": { "link_severity": "warn" }
|
||||
},
|
||||
"settings": {
|
||||
"nuwiki": {
|
||||
"wiki_root": "$WIKI_DIR",
|
||||
"file_extension": ".wiki",
|
||||
"syntax": "vimwiki",
|
||||
"log_level": "info",
|
||||
"toc_header_level": 2,
|
||||
"html_header_numbering": 2,
|
||||
"html_header_numbering_sym": " -",
|
||||
"diagnostic": { "link_severity": "warn" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"coc.preferences.jumpCommand": "$COC_JUMP"
|
||||
}
|
||||
EOF
|
||||
}
|
||||
@@ -146,6 +114,12 @@ let g:nuwiki_file_extension = '.wiki'
|
||||
let g:nuwiki_syntax = 'vimwiki'
|
||||
let g:nuwiki_diary_rel_path = 'diary'
|
||||
let g:nuwiki_log_level = 'info'
|
||||
" nuwiki auto-registers itself with coc from these globals (no coc-settings.json
|
||||
" languageserver block). Display settings exercise the global shorthand:
|
||||
" :NuwikiTOC writes `== Contents ==` (level 2) and HTML export numbers headings.
|
||||
let g:nuwiki_toc_header_level = 2
|
||||
let g:nuwiki_html_header_numbering = 2
|
||||
let g:nuwiki_html_header_numbering_sym = ' -'
|
||||
|
||||
filetype plugin indent on
|
||||
syntax enable
|
||||
|
||||
Reference in New Issue
Block a user