From 8d11f7daefcf4b4e2bf1ef4ac8b9d397dcee40e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Thu, 21 May 2026 22:45:04 -0300 Subject: [PATCH] fix(lsp): send g:nuwiki_wikis to the server so per-wiki roots are known MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- autoload/nuwiki/lsp.vim | 10 +++++++++- lua/nuwiki/lsp.lua | 33 ++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/autoload/nuwiki/lsp.vim b/autoload/nuwiki/lsp.vim index ab09a59..1238ea0 100644 --- a/autoload/nuwiki/lsp.vim +++ b/autoload/nuwiki/lsp.vim @@ -76,10 +76,18 @@ function! s:bin_path() abort endfunction function! s:settings() abort - return { + let l:cfg = { \ 'wiki_root': get(g:, 'nuwiki_wiki_root', '~/vimwiki'), \ 'file_extension': get(g:, 'nuwiki_file_extension', '.wiki'), \ 'syntax': get(g:, 'nuwiki_syntax', 'vimwiki'), \ 'log_level': get(g:, 'nuwiki_log_level', '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. + if exists('g:nuwiki_wikis') && !empty(g:nuwiki_wikis) + let l:cfg['wikis'] = g:nuwiki_wikis + endif + return l:cfg endfunction diff --git a/lua/nuwiki/lsp.lua b/lua/nuwiki/lsp.lua index 1767c9d..977c9cc 100644 --- a/lua/nuwiki/lsp.lua +++ b/lua/nuwiki/lsp.lua @@ -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()