feat(config): vimwiki drop-in config + global per-wiki defaults
CI / cargo fmt --check (push) Successful in 31s
CI / cargo clippy (push) Successful in 32s
CI / cargo test (push) Successful in 41s
CI / editor keymaps (push) Successful in 1m53s

Two related config-ergonomics features for vimwiki migrants, sharing the
same scalar-global machinery.

1. Upstream g:vimwiki_* drop-in (Vim client). When nuwiki isn't configured
   natively, the Vim client reads g:vimwiki_list + g:vimwiki_* globals and
   translates them into nuwiki's schema: per-wiki path->root,
   path_html->html_path, template_*, css_name, auto_export/auto_toc,
   syntax, ext->file_extension, index, diary_*, name. g:nuwiki_* always
   wins. Lets a vimwiki user drop in nuwiki without rewriting config.

2. Global per-wiki defaults (both clients). A display/generation setting
   given once at the top level — g:nuwiki_<key> / setup({<key>=…}) /
   g:vimwiki_<key> — is folded into every wiki as a default; a per-wiki
   value overrides it (vimwiki's model). Covers toc_header(_level),
   toc_link_format, links_header(_level), tags_header(_level),
   html_header_numbering(_sym), links_space_char, list_margin, listsyms,
   listsym_rejected, and the auto_* toggles. Only values the user
   explicitly set fold — built-in defaults don't (added config.user
   tracking on the Lua side so a default toc_header_level=1 isn't pushed
   onto every wiki). User config tables are never mutated.

Both clients kept in lock-step (config-parity golden enforces identical
payloads). New harnesses test-vimwiki-compat-vim (18) and
test-global-shorthand (8), wired into CI. Server test
vimwiki_compat_payload_sets_toc_level_per_wiki. Docs in README +
known-issues.md (drop-in is currently Vim-only). Rust 573 passed, clippy
clean, all harnesses green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 23:37:10 +00:00
parent fc0d74bfbe
commit 9d89e01ed8
11 changed files with 465 additions and 7 deletions
+113 -5
View File
@@ -12,6 +12,97 @@ let s:plugin_root = fnamemodify(resolve(expand('<sfile>:p')), ':h:h:h')
let s:started = 0
" ===== Upstream vimwiki config compatibility =====
"
" nuwiki is a drop-in vimwiki replacement, so a user who keeps their original
" `g:vimwiki_list` + `g:vimwiki_*` globals shouldn't have to rewrite anything.
" These tables translate the upstream names into the server's config schema.
" nuwiki-native config (`g:nuwiki_wikis` / `g:nuwiki_*`) always wins.
" Per-wiki dict keys: upstream `g:vimwiki_list[i]` key -> server key.
let s:vimwiki_wiki_map = {
\ 'path': 'root',
\ 'path_html': 'html_path',
\ 'template_path': 'template_path',
\ 'template_default': 'template_default',
\ 'template_ext': 'template_ext',
\ 'css_name': 'css_name',
\ 'auto_export': 'auto_export',
\ 'auto_toc': 'auto_toc',
\ 'syntax': 'syntax',
\ 'ext': 'file_extension',
\ 'index': 'index',
\ 'diary_rel_path': 'diary_rel_path',
\ 'diary_index': 'diary_index',
\ 'name': 'name',
\ }
" Global scalar settings vimwiki applies to every wiki (via wikilocal
" defaults): upstream suffix (`g:vimwiki_<suffix>`) -> server key. The server
" reads these per-wiki, so we fold them into each wiki entry (and into the
" single-wiki shorthand payload).
let s:scalar_global_map = {
\ 'toc_header': 'toc_header',
\ 'toc_header_level': 'toc_header_level',
\ 'toc_link_format': 'toc_link_format',
\ 'links_header': 'links_header',
\ 'links_header_level': 'links_header_level',
\ 'tags_header': 'tags_header',
\ 'tags_header_level': 'tags_header_level',
\ 'html_header_numbering': 'html_header_numbering',
\ 'html_header_numbering_sym': 'html_header_numbering_sym',
\ 'links_space_char': 'links_space_char',
\ 'list_margin': 'list_margin',
\ 'listsyms': 'listsyms',
\ 'listsym_rejected': 'listsym_rejected',
\ 'auto_export': 'auto_export',
\ 'auto_toc': 'auto_toc',
\ 'auto_generate_links': 'auto_generate_links',
\ 'auto_generate_tags': 'auto_generate_tags',
\ 'auto_diary_index': 'auto_diary_index',
\ }
" Resolve the per-wiki scalar globals: vimwiki values first (compat), then
" nuwiki-native `g:nuwiki_<key>` overrides on top.
function! s:scalar_globals() abort
let l:g = {}
for [l:src, l:dst] in items(s:scalar_global_map)
if exists('g:vimwiki_' . l:src)
let l:g[l:dst] = get(g:, 'vimwiki_' . l:src)
endif
endfor
for l:dst in values(s:scalar_global_map)
if exists('g:nuwiki_' . l:dst)
let l:g[l:dst] = get(g:, 'nuwiki_' . l:dst)
endif
endfor
return l:g
endfunction
" Build nuwiki's `wikis` list from an upstream `g:vimwiki_list`, folding the
" global scalar settings into each entry. Returns [] when unset/malformed.
function! s:wikis_from_vimwiki() abort
if !exists('g:vimwiki_list') || type(g:vimwiki_list) != type([]) || empty(g:vimwiki_list)
return []
endif
let l:globals = s:scalar_globals()
let l:wikis = []
for l:vw in g:vimwiki_list
if type(l:vw) != type({}) | continue | endif
let l:w = copy(l:globals)
for [l:src, l:dst] in items(s:vimwiki_wiki_map)
if has_key(l:vw, l:src)
let l:w[l:dst] = l:vw[l:src]
endif
endfor
" A wiki needs a root; skip entries without one.
if has_key(l:w, 'root')
call add(l:wikis, l:w)
endif
endfor
return l:wikis
endfunction
function! nuwiki#lsp#start() abort
if s:started
return
@@ -89,12 +180,29 @@ function! s:settings() abort
\ 'link_severity': get(g:, 'nuwiki_link_severity', 'warn'),
\ },
\ }
" Include the per-wiki list when configured via g:nuwiki_wikis so the
" server knows each wiki's root, diary path, etc. Without this it only
" sees wiki_root and resolves links relative to that directory instead
" of the individual wiki's root.
" Global scalar settings (g:vimwiki_* then g:nuwiki_* overrides) act as
" defaults applied to every wiki, vimwiki-style. A per-wiki value always
" wins. Resolved once and folded into whichever wiki shape we send.
let l:globals = s:scalar_globals()
" Wiki list resolution, in priority order:
" 1. g:nuwiki_wikis (native multi-wiki config)
" 2. g:vimwiki_list (upstream vimwiki config — drop-in compat)
" 3. wiki_root shorthand (single wiki)
" Without a list the server only sees wiki_root and resolves links relative
" to that directory instead of each individual wiki's root.
if exists('g:nuwiki_wikis') && !empty(g:nuwiki_wikis)
let l:cfg['wikis'] = g:nuwiki_wikis
let l:cfg['wikis'] = map(copy(g:nuwiki_wikis),
\ {_, w -> extend(copy(l:globals), w, 'force')})
else
let l:vw_wikis = s:wikis_from_vimwiki()
if !empty(l:vw_wikis)
let l:cfg['wikis'] = l:vw_wikis
else
" Single-wiki shorthand: fold the global scalars into the top-level
" payload so the server's single-wiki desugaring honours them.
call extend(l:cfg, l:globals, 'force')
endif
endif
return l:cfg
endfunction