fix(lsp): send g:nuwiki_wikis to the server so per-wiki roots are known
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:
@@ -76,10 +76,18 @@ function! s:bin_path() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:settings() abort
|
function! s:settings() abort
|
||||||
return {
|
let l:cfg = {
|
||||||
\ 'wiki_root': get(g:, 'nuwiki_wiki_root', '~/vimwiki'),
|
\ 'wiki_root': get(g:, 'nuwiki_wiki_root', '~/vimwiki'),
|
||||||
\ 'file_extension': get(g:, 'nuwiki_file_extension', '.wiki'),
|
\ 'file_extension': get(g:, 'nuwiki_file_extension', '.wiki'),
|
||||||
\ 'syntax': get(g:, 'nuwiki_syntax', 'vimwiki'),
|
\ 'syntax': get(g:, 'nuwiki_syntax', 'vimwiki'),
|
||||||
\ 'log_level': get(g:, 'nuwiki_log_level', 'warn'),
|
\ '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
|
endfunction
|
||||||
|
|||||||
+26
-7
@@ -14,25 +14,33 @@ local function command()
|
|||||||
return { install.expected_path() }
|
return { install.expected_path() }
|
||||||
end
|
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
|
--- `initializationOptions` payload: the server reads it once at
|
||||||
--- `initialize` time via `Config::from_init_params`. This is what
|
--- `initialize` time via `Config::from_init_params`. This is what
|
||||||
--- delivers `wiki_root`/`wikis`/HTML/diary config to Rust.
|
--- delivers `wiki_root`/`wikis`/HTML/diary config to Rust.
|
||||||
local function init_options()
|
local function init_options()
|
||||||
return config.options
|
return resolved_opts()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- `settings` payload: the same shape, but sent via
|
--- `settings` payload: the same shape, but sent via
|
||||||
--- `workspace/didChangeConfiguration` after startup. Lets the server
|
--- `workspace/didChangeConfiguration` after startup. Lets the server
|
||||||
--- pick up config changes without a restart.
|
--- pick up config changes without a restart.
|
||||||
local function server_settings()
|
local function server_settings()
|
||||||
return {
|
return { nuwiki = resolved_opts() }
|
||||||
nuwiki = config.options,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function root_dir_for(buf_file)
|
local function root_dir_for(buf_file)
|
||||||
-- Walk up from the buffer until we hit a workspace marker, or fall back
|
-- Walk up from the buffer until we hit a workspace marker.
|
||||||
-- to the configured wiki_root.
|
|
||||||
local found = vim.fs.find(
|
local found = vim.fs.find(
|
||||||
{ '.git', '.nuwiki' },
|
{ '.git', '.nuwiki' },
|
||||||
{ upward = true, path = vim.fs.dirname(buf_file) }
|
{ upward = true, path = vim.fs.dirname(buf_file) }
|
||||||
@@ -40,7 +48,18 @@ local function root_dir_for(buf_file)
|
|||||||
if found then
|
if found then
|
||||||
return vim.fs.dirname(found)
|
return vim.fs.dirname(found)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function M.register()
|
function M.register()
|
||||||
|
|||||||
Reference in New Issue
Block a user