From 0d1a73a3ba6d8e495a2386cbf98160c676053fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Sat, 6 Jun 2026 01:34:24 +0000 Subject: [PATCH] feat(config): bridge setup({wikis}) to g:nuwiki_wikis for VimL plugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Lua-only `setup({ wikis = … })` config is invisible to the VimL side: the buffer helpers in autoload/nuwiki/config.vim and the vimwiki compat shim (autoload/vimwiki/vars.vim, which third-party plugins like vimwiki-sync call via vimwiki#vars#get_wikilocal) read g:nuwiki_wikis. So a Neovim user who migrated from g:vimwiki_list to native setup({wikis}) would break vimwiki-sync (it'd resolve the default ~/vimwiki). setup() now publishes the resolved wiki list to g:nuwiki_wikis when the config came from setup() opts (the only case VimL can't already see — g:nuwiki_wikis / g:vimwiki_list configs are global and visible). Verified vimwiki#vars#get_wikilocal('path', n) returns the right roots from a pure-Lua setup() config. test-global-shorthand grows two bridge checks (17). Goldens + keymap harnesses green. Co-Authored-By: Claude Opus 4.8 --- development/tests/test-global-shorthand.lua | 10 ++++++++++ lua/nuwiki/init.lua | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/development/tests/test-global-shorthand.lua b/development/tests/test-global-shorthand.lua index 240eb08..65bd54b 100644 --- a/development/tests/test-global-shorthand.lua +++ b/development/tests/test-global-shorthand.lua @@ -71,6 +71,16 @@ vim.g.nuwiki_wikis = nil vim.g.vimwiki_list = nil vim.g.vimwiki_toc_header_level = nil +-- ----- setup({ wikis }) bridges the Lua config to VimL (g:nuwiki_wikis) ----- +-- So buffer-side VimL helpers + the vimwiki-sync compat shim see the same +-- wikis as the LSP, even though setup() config lives only in Lua. +require('nuwiki').setup({ wikis = { { root = '/tmp/a', name = 'A' }, { root = '/tmp/b' } } }) +check('setup() bridges to g:nuwiki_wikis', + vim.g.nuwiki_wikis ~= nil and #vim.g.nuwiki_wikis == 2) +check('bridged wiki root visible to VimL', + vim.g.nuwiki_wikis and vim.g.nuwiki_wikis[1].root == '/tmp/a') +vim.g.nuwiki_wikis = nil + local f = assert(io.open(os.getenv('NUWIKI_GS_OUT'), 'w')) f:write(table.concat(out, '\n') .. '\n') f:close() diff --git a/lua/nuwiki/init.lua b/lua/nuwiki/init.lua index 9443799..015d1e9 100644 --- a/lua/nuwiki/init.lua +++ b/lua/nuwiki/init.lua @@ -93,6 +93,17 @@ end function M.setup(opts) config.apply(opts or {}) + -- Bridge a Lua-only `setup({ wikis = … })` config to VimL. The buffer-side + -- VimL helpers (autoload/nuwiki/config.vim) and the vimwiki compat shim + -- (autoload/vimwiki/vars.vim — used by third-party plugins such as + -- vimwiki-sync) read `g:nuwiki_wikis`, which can't see a config that only + -- lives in Lua. Publishing the resolved list keeps both worlds in sync. (A + -- `g:nuwiki_wikis` / `g:vimwiki_list` config is already VimL-visible, so this + -- only fires for the pure-`setup()` case.) + if type(config.options.wikis) == 'table' and #config.options.wikis > 0 then + vim.g.nuwiki_wikis = config.wikis() + end + -- Neovim 0.7+ resolves filetypes via `vim.filetype.match` before any -- `ftdetect/*.vim` autocmd fires, and its bundled rule for `*.wiki` -- returns `mediawiki`. Register an authoritative rule here so this