9d6d28a1b6
The g:vimwiki_* drop-in only fed the LSP payload (lsp.vim s:settings). The buffer-side commands — <Leader>ww (wiki_index), :VimwikiSearch, auto_chdir, diary, completion — resolve the wiki list independently via s:wiki_cfg / nuwiki#commands#wiki_list, which read only g:nuwiki_wikis / g:nuwiki_wiki_root. So with a g:vimwiki_list config the server knew the wikis but <Leader>ww fell back to the default ~/vimwiki and opened an empty index. Extract the resolution into a single source of truth, autoload/nuwiki/config.vim (nuwiki#config#wikis / #scalar_globals), which resolves g:nuwiki_wikis or an upstream g:vimwiki_list and folds the global scalar defaults. lsp.vim (payload), commands.vim, and diary.vim all route through it — also dedups the s:wiki_cfg copy that lived in both commands.vim and diary.vim. Regression guard in test-vimwiki-compat-vim: nuwiki#commands#wiki_list() must resolve the g:vimwiki_list roots (21 checks). All Vim harnesses + config-parity goldens green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
104 lines
4.2 KiB
VimL
104 lines
4.2 KiB
VimL
" autoload/nuwiki/config.vim — single source of truth for the configured wiki
|
|
" list, shared by the LSP payload (lsp.vim) and the buffer-side commands
|
|
" (commands.vim, diary.vim, complete.vim).
|
|
"
|
|
" Resolves wikis from g:nuwiki_wikis (native) or, when that's unset, an upstream
|
|
" g:vimwiki_list (drop-in compatibility), translating upstream key names and
|
|
" folding the global scalar defaults (g:vimwiki_* / g:nuwiki_*) into each entry.
|
|
" Everything downstream — `<Leader>ww`, link resolution, the server payload —
|
|
" then sees the same wikis.
|
|
|
|
" Per-wiki dict keys: upstream `g:vimwiki_list[i]` key -> nuwiki/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>`) -> nuwiki/server key.
|
|
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! nuwiki#config#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
|
|
|
|
" Translate an upstream g:vimwiki_list into nuwiki's wiki list, folding the
|
|
" given global scalars into each entry. Returns [] when unset/malformed.
|
|
function! s:wikis_from_vimwiki(globals) abort
|
|
if !exists('g:vimwiki_list') || type(g:vimwiki_list) != type([]) || empty(g:vimwiki_list)
|
|
return []
|
|
endif
|
|
let l:wikis = []
|
|
for l:vw in g:vimwiki_list
|
|
if type(l:vw) != type({}) | continue | endif
|
|
let l:w = copy(a: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
|
|
if has_key(l:w, 'root')
|
|
call add(l:wikis, l:w)
|
|
endif
|
|
endfor
|
|
return l:wikis
|
|
endfunction
|
|
|
|
" The configured wikis as normalized dicts (nuwiki/server key names), with the
|
|
" global scalar defaults folded in (per-wiki value wins). Priority:
|
|
" 1. g:nuwiki_wikis (native)
|
|
" 2. g:vimwiki_list (upstream drop-in)
|
|
" Returns [] when neither is set — callers fall back to the single-wiki
|
|
" shorthand (g:nuwiki_wiki_root).
|
|
function! nuwiki#config#wikis() abort
|
|
let l:globals = nuwiki#config#scalar_globals()
|
|
if exists('g:nuwiki_wikis') && !empty(g:nuwiki_wikis)
|
|
return map(copy(g:nuwiki_wikis), {_, w -> extend(copy(l:globals), w, 'force')})
|
|
endif
|
|
return s:wikis_from_vimwiki(l:globals)
|
|
endfunction
|