feat(config): vimwiki drop-in config + global per-wiki defaults
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:
@@ -0,0 +1,54 @@
|
||||
-- development/tests/test-global-shorthand.lua — Neovim client global
|
||||
-- shorthand: a per-wiki setting given once at the top level (setup() or
|
||||
-- g:nuwiki_<key>) is folded into every wiki as a default, and a per-wiki
|
||||
-- value overrides it. Mirror of the Vim test-vimwiki-compat checks.
|
||||
--
|
||||
-- Writes PASS/FAIL lines to $NUWIKI_GS_OUT; the wrapper fails on any FAIL.
|
||||
|
||||
local config = require('nuwiki.config')
|
||||
local lsp = require('nuwiki.lsp')
|
||||
|
||||
local out = {}
|
||||
local function check(desc, cond)
|
||||
table.insert(out, (cond and 'PASS ' or 'FAIL ') .. desc)
|
||||
end
|
||||
|
||||
-- ----- setup() top-level scalar folds into every wiki; per-wiki wins -----
|
||||
config.apply({
|
||||
toc_header_level = 2,
|
||||
html_header_numbering = 2,
|
||||
wikis = {
|
||||
{ root = '/tmp/one', name = 'One' },
|
||||
{ root = '/tmp/two', name = 'Two', toc_header_level = 3 },
|
||||
},
|
||||
})
|
||||
local io1 = lsp.init_options()
|
||||
check('w0 inherits global level', io1.wikis[1].toc_header_level == 2)
|
||||
check('w0 inherits numbering', io1.wikis[1].html_header_numbering == 2)
|
||||
check('w1 per-wiki override wins', io1.wikis[2].toc_header_level == 3)
|
||||
check('w1 still inherits numbering', io1.wikis[2].html_header_numbering == 2)
|
||||
|
||||
-- The user's setup table must not be mutated by the fold.
|
||||
check('no mutation of user wikis', config.user.wikis[1].toc_header_level == nil)
|
||||
|
||||
-- ----- built-in defaults are NOT folded (only explicit user values) -----
|
||||
config.apply({
|
||||
wikis = { { root = '/tmp/x', name = 'X' } },
|
||||
})
|
||||
local io2 = lsp.init_options()
|
||||
check('default toc_header not folded', io2.wikis[1].toc_header == nil)
|
||||
check('default level not folded', io2.wikis[1].toc_header_level == nil)
|
||||
|
||||
-- ----- g:nuwiki_<key> acts as a global too -----
|
||||
config.apply({
|
||||
wikis = { { root = '/tmp/y', name = 'Y' } },
|
||||
})
|
||||
vim.g.nuwiki_toc_header_level = 5
|
||||
local io3 = lsp.init_options()
|
||||
check('g:nuwiki_ global folds', io3.wikis[1].toc_header_level == 5)
|
||||
vim.g.nuwiki_toc_header_level = nil
|
||||
|
||||
local f = assert(io.open(os.getenv('NUWIKI_GS_OUT'), 'w'))
|
||||
f:write(table.concat(out, '\n') .. '\n')
|
||||
f:close()
|
||||
vim.cmd('qa!')
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# development/tests/test-global-shorthand.sh — Neovim client global-shorthand
|
||||
# folding (vimwiki-style per-wiki defaults). Runs test-global-shorthand.lua
|
||||
# under headless Neovim; that script asserts the init_options payload folds a
|
||||
# top-level / g:nuwiki_* setting into every wiki, lets a per-wiki value
|
||||
# override it, and does NOT fold built-in defaults.
|
||||
#
|
||||
# Exit code: 0 when every check passes, 1 on any FAIL or missing output.
|
||||
# Skips (exit 0) when nvim is not installed.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
log() { printf '\033[1;34m[global-shorthand]\033[0m %s\n' "$*"; }
|
||||
|
||||
if ! command -v nvim >/dev/null 2>&1; then
|
||||
log 'nvim not installed — skipping'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TMP="$(mktemp -d -t nuwiki-gs-test-XXXXXX)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
OUT="$TMP/gs.out"
|
||||
INIT="$TMP/init.lua"
|
||||
cat > "$INIT" <<EOF
|
||||
vim.opt.runtimepath:prepend('$REPO_ROOT')
|
||||
EOF
|
||||
|
||||
log 'running Neovim global-shorthand harness…'
|
||||
NUWIKI_GS_OUT="$OUT" \
|
||||
timeout 30 nvim --clean -u "$INIT" --headless \
|
||||
-c "luafile $REPO_ROOT/development/tests/test-global-shorthand.lua" \
|
||||
>"$TMP/nvim.log" 2>&1 || true
|
||||
|
||||
if [[ ! -f "$OUT" ]]; then
|
||||
echo 'global-shorthand harness produced no output' >&2
|
||||
echo '--- nvim log ---' >&2
|
||||
cat "$TMP/nvim.log" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat "$OUT"
|
||||
PASSED="$(grep -c '^PASS ' "$OUT" || true)"
|
||||
FAILED="$(grep -c '^FAIL ' "$OUT" || true)"
|
||||
echo "SUMMARY: ${PASSED} passed, ${FAILED} failed"
|
||||
|
||||
if [[ "$FAILED" -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
log 'global shorthand OK ✓'
|
||||
exit 0
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# development/tests/test-vimwiki-compat-vim.sh — upstream-vimwiki config
|
||||
# drop-in compatibility for the Vim client.
|
||||
#
|
||||
# Runs test-vimwiki-compat-vim.vim under headless Vim; that script sets an
|
||||
# upstream `g:vimwiki_list` + `g:vimwiki_*` config and asserts
|
||||
# nuwiki#lsp#settings() translates it into the server's schema (per-wiki key
|
||||
# remap + global scalar settings folded into each wiki). Also checks that
|
||||
# nuwiki-native config takes precedence.
|
||||
#
|
||||
# Exit code: 0 when every check passes, 1 on any FAIL or missing output.
|
||||
# Skips (exit 0) when vim is not installed.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
log() { printf '\033[1;34m[vimwiki-compat]\033[0m %s\n' "$*"; }
|
||||
|
||||
if ! command -v vim >/dev/null 2>&1; then
|
||||
log 'vim not installed — skipping'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TMP="$(mktemp -d -t nuwiki-vwc-test-XXXXXX)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
OUT="$TMP/vwc.out"
|
||||
|
||||
VIMRC="$TMP/vimrc"
|
||||
cat > "$VIMRC" <<EOF
|
||||
set nocompatible
|
||||
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
||||
EOF
|
||||
|
||||
log 'running Vim vimwiki-compat harness…'
|
||||
NUWIKI_VWC_OUT="$OUT" \
|
||||
timeout 30 vim -e -s -u "$VIMRC" \
|
||||
-c "source $REPO_ROOT/development/tests/test-vimwiki-compat-vim.vim" \
|
||||
</dev/null >"$TMP/vim.log" 2>&1 || true
|
||||
|
||||
if [[ ! -f "$OUT" ]]; then
|
||||
echo 'vimwiki-compat harness produced no output' >&2
|
||||
echo '--- vim log ---' >&2
|
||||
cat "$TMP/vim.log" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat "$OUT"
|
||||
PASSED="$(grep -c '^PASS ' "$OUT" || true)"
|
||||
FAILED="$(grep -c '^FAIL ' "$OUT" || true)"
|
||||
echo "SUMMARY: ${PASSED} passed, ${FAILED} failed"
|
||||
|
||||
if [[ "$FAILED" -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
log 'vimwiki config compat OK ✓'
|
||||
exit 0
|
||||
@@ -0,0 +1,78 @@
|
||||
" development/tests/test-vimwiki-compat-vim.vim — upstream-vimwiki config
|
||||
" drop-in compatibility for the Vim client.
|
||||
"
|
||||
" Sourced by test-vimwiki-compat-vim.sh under headless Vim. Sets an upstream
|
||||
" `g:vimwiki_list` + `g:vimwiki_*` config and asserts nuwiki#lsp#settings()
|
||||
" translates it into the server's schema. Writes PASS/FAIL to
|
||||
" $NUWIKI_VWC_OUT; the wrapper fails on any FAIL.
|
||||
|
||||
let s:out = []
|
||||
function! s:check(desc, cond) abort
|
||||
call add(s:out, (a:cond ? 'PASS ' : 'FAIL ') . a:desc)
|
||||
endfunction
|
||||
|
||||
" ----- upstream vimwiki config (no nuwiki-native vars set) -----
|
||||
let g:vimwiki_toc_header_level = 2
|
||||
let g:vimwiki_html_header_numbering = 2
|
||||
let g:vimwiki_html_header_numbering_sym = ' -'
|
||||
let s:personal = {}
|
||||
let s:personal.path = '~/.vimwiki/personal_wiki'
|
||||
let s:personal.path_html = '~/public_html/personal_wiki'
|
||||
let s:personal.template_default = 'default'
|
||||
let s:personal.template_ext = '.tpl'
|
||||
let s:personal.auto_export = 1
|
||||
let s:ifood = {}
|
||||
let s:ifood.path = '~/.vimwiki/ifood_wiki'
|
||||
let g:vimwiki_list = [s:personal, s:ifood]
|
||||
|
||||
let s:cfg = nuwiki#lsp#settings()
|
||||
|
||||
call s:check('has wikis list', has_key(s:cfg, 'wikis'))
|
||||
call s:check('two wikis', has_key(s:cfg, 'wikis') && len(s:cfg.wikis) == 2)
|
||||
let s:w0 = get(s:cfg, 'wikis', [{}])[0]
|
||||
let s:w1 = get(s:cfg, 'wikis', [{},{}])[1]
|
||||
call s:check('w0 path->root', get(s:w0, 'root', '') ==# '~/.vimwiki/personal_wiki')
|
||||
call s:check('w0 path_html->html_path', get(s:w0, 'html_path', '') ==# '~/public_html/personal_wiki')
|
||||
call s:check('w0 template_default', get(s:w0, 'template_default', '') ==# 'default')
|
||||
call s:check('w0 auto_export', get(s:w0, 'auto_export', 0) == 1)
|
||||
call s:check('w0 toc_header_level=2', get(s:w0, 'toc_header_level', 0) == 2)
|
||||
call s:check('w0 html_numbering=2', get(s:w0, 'html_header_numbering', 0) == 2)
|
||||
call s:check('w0 numbering_sym', get(s:w0, 'html_header_numbering_sym', '') ==# ' -')
|
||||
call s:check('w1 root', get(s:w1, 'root', '') ==# '~/.vimwiki/ifood_wiki')
|
||||
call s:check('w1 globals applied', get(s:w1, 'toc_header_level', 0) == 2)
|
||||
|
||||
" ----- nuwiki-native config wins over vimwiki -----
|
||||
let g:nuwiki_wikis = [{'root': '~/native', 'name': 'native'}]
|
||||
let s:cfg2 = nuwiki#lsp#settings()
|
||||
call s:check('native g:nuwiki_wikis wins',
|
||||
\ len(get(s:cfg2, 'wikis', [])) == 1
|
||||
\ && get(s:cfg2.wikis[0], 'root', '') ==# '~/native')
|
||||
unlet g:nuwiki_wikis
|
||||
|
||||
" ----- nuwiki-native scalar overrides the vimwiki global -----
|
||||
let g:vimwiki_list = []
|
||||
let g:nuwiki_toc_header_level = 4
|
||||
let s:cfg3 = nuwiki#lsp#settings()
|
||||
" No wikis list now (vimwiki_list empty) → scalar folded into top-level.
|
||||
call s:check('native scalar override', get(s:cfg3, 'toc_header_level', 0) == 4)
|
||||
unlet g:nuwiki_toc_header_level
|
||||
|
||||
" ----- global shorthand on native g:nuwiki_wikis (vimwiki-style) -----
|
||||
" A global default applies to every wiki; a per-wiki value overrides it.
|
||||
let g:nuwiki_toc_header_level = 2
|
||||
let g:nuwiki_html_header_numbering = 2
|
||||
let g:nuwiki_wikis = [
|
||||
\ {'root': '~/w1', 'name': 'One'},
|
||||
\ {'root': '~/w2', 'name': 'Two', 'toc_header_level': 3},
|
||||
\ ]
|
||||
let s:cfg4 = nuwiki#lsp#settings()
|
||||
let s:g0 = s:cfg4.wikis[0]
|
||||
let s:g1 = s:cfg4.wikis[1]
|
||||
call s:check('global folds into wiki 0', get(s:g0, 'toc_header_level', 0) == 2)
|
||||
call s:check('global numbering folds', get(s:g0, 'html_header_numbering', 0) == 2)
|
||||
call s:check('per-wiki override wins', get(s:g1, 'toc_header_level', 0) == 3)
|
||||
call s:check('global still folds elsewhere', get(s:g1, 'html_header_numbering', 0) == 2)
|
||||
" The user's original dict must not be mutated by the fold.
|
||||
call s:check('no mutation of g:nuwiki_wikis', !has_key(g:nuwiki_wikis[0], 'toc_header_level'))
|
||||
|
||||
call writefile(s:out, $NUWIKI_VWC_OUT)
|
||||
Reference in New Issue
Block a user