fix(lsp): send g:nuwiki_wikis to the server so per-wiki roots are known
CI / cargo fmt --check (push) Successful in 34s
CI / cargo clippy (push) Successful in 19s
CI / cargo test (push) Successful in 39s
CI / editor keymaps (push) Successful in 1m46s

The server received only wiki_root (the parent directory) and had no
knowledge of the per-wiki sub-roots configured in g:nuwiki_wikis / the
setup() wikis list. It therefore resolved all links relative to the
parent root, causing every link in a sub-wiki to appear broken.

Vim path (autoload/nuwiki/lsp.vim):
  s:settings() now includes a 'wikis' key when g:nuwiki_wikis is set,
  so the initialization_options and settings payloads carry the full
  per-wiki config (root, diary_rel_path, file_extension, …).

Lua path (lua/nuwiki/lsp.lua):
  Add resolved_opts() which merges vim.g.nuwiki_wikis into
  config.options.wikis when the user configures via VimL rather than
  setup({wikis=…}). init_options(), server_settings(), and the
  pre-0.11 root_dir_for() fallback all use resolved_opts() so the
  server receives the correct per-wiki roots in every code path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-21 22:45:04 -03:00
parent b3e2a72023
commit 8d11f7daef
2 changed files with 35 additions and 8 deletions
+26 -7
View File
@@ -14,25 +14,33 @@ local function command()
return { install.expected_path() }
end
-- Merge g:nuwiki_wikis (VimL config) into opts.wikis when the user has not
-- passed wikis through setup(). This lets users who configure via a .vim
-- file avoid duplicating the list in their Lua setup() call.
local function resolved_opts()
local opts = config.options
if not opts.wikis and vim.g.nuwiki_wikis then
opts = vim.tbl_extend('force', opts, { wikis = vim.g.nuwiki_wikis })
end
return opts
end
--- `initializationOptions` payload: the server reads it once at
--- `initialize` time via `Config::from_init_params`. This is what
--- delivers `wiki_root`/`wikis`/HTML/diary config to Rust.
local function init_options()
return config.options
return resolved_opts()
end
--- `settings` payload: the same shape, but sent via
--- `workspace/didChangeConfiguration` after startup. Lets the server
--- pick up config changes without a restart.
local function server_settings()
return {
nuwiki = config.options,
}
return { nuwiki = resolved_opts() }
end
local function root_dir_for(buf_file)
-- Walk up from the buffer until we hit a workspace marker, or fall back
-- to the configured wiki_root.
-- Walk up from the buffer until we hit a workspace marker.
local found = vim.fs.find(
{ '.git', '.nuwiki' },
{ upward = true, path = vim.fs.dirname(buf_file) }
@@ -40,7 +48,18 @@ local function root_dir_for(buf_file)
if found then
return vim.fs.dirname(found)
end
return vim.fn.expand(config.options.wiki_root)
-- For multi-wiki setups, find the wiki whose root contains buf_file.
local opts = resolved_opts()
if opts.wikis then
local buf_norm = vim.fs.normalize(buf_file)
for _, w in ipairs(opts.wikis) do
local root = vim.fn.expand(w.root or '')
if root ~= '' and buf_norm:sub(1, #root) == root then
return root
end
end
end
return vim.fn.expand(opts.wiki_root or '~/vimwiki')
end
function M.register()