fix(wiki): build wiki picker list from config so it works before opening a file
CI / cargo fmt --check (push) Successful in 36s
CI / cargo clippy (push) Successful in 21s
CI / cargo test (push) Successful in 27s
CI / editor keymaps (push) Successful in 1m14s

The picker fetched the wiki list via workspace/executeCommand, but the LSP
only starts once a vimwiki buffer exists — so a wiki could not be selected
until one was already open (chicken-and-egg). Read the list straight from
config instead (g:nuwiki_wikis / scalar fallback, the same source as
open_wiki_path) and open the chosen index directly; that auto-starts the
server via the FileType autocmd.

- Vim: new public nuwiki#commands#wiki_list(); wiki_ui_select() uses it +
  inputlist() + :edit. Global :VimwikiUISelect / :NuwikiUISelect commands.
- Neovim: config.wiki_cfg(n) + config.wiki_list() (init.lua delegates);
  commands.wiki_ui_select() uses them + vim.ui.select + :edit; global
  VimwikiUISelect / NuwikiUISelect user commands registered in setup().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 20:04:31 -03:00
parent d6672fe218
commit 7f6d811a47
7 changed files with 156 additions and 64 deletions
+24
View File
@@ -321,6 +321,30 @@ call s:record(
\ 'conceal.cursor_line_revealed_in_normal_mode',
\ '&l:concealcursor=' . &l:concealcursor)
" ===== Wiki picker (config-driven, no LSP) =====
" The picker builds its list straight from config so it works from any buffer
" before the LSP (which only starts on a wiki buffer) is running.
let g:nuwiki_wikis = [
\ {'name': 'Personal', 'root': '/tmp/nuwiki-a'},
\ {'name': 'Work', 'root': '/tmp/nuwiki-b', 'file_extension': 'md'},
\ ]
let s:wl = nuwiki#commands#wiki_list()
call s:record(
\ len(s:wl) == 2 ? 1 : 0,
\ 'wiki_select.lists_all_configured_wikis',
\ 'count=' . len(s:wl))
call s:record(
\ get(get(s:wl, 0, {}), 'name', '') ==# 'Personal'
\ && get(get(s:wl, 1, {}), 'name', '') ==# 'Work' ? 1 : 0,
\ 'wiki_select.preserves_names_and_order',
\ 'names=' . string(map(copy(s:wl), 'get(v:val, "name", "")')))
call s:record(
\ get(get(s:wl, 1, {}), 'ext', '') ==# '.md' ? 1 : 0,
\ 'wiki_select.honours_per_wiki_extension',
\ 'ext=' . get(get(s:wl, 1, {}), 'ext', ''))
unlet g:nuwiki_wikis
" ===== Wrap up =====
call add(s:results, '')
+19
View File
@@ -492,6 +492,25 @@ vim.defer_fn(function()
-- a populated diary, but at least confirm the maps fire without
-- error.
-- ===== Wiki picker (config-driven, no LSP) =====
-- The picker must build its list from config so it works from any buffer
-- before the server attaches.
tobj_case('wiki_select.config_list_reads_g_var', function()
vim.g.nuwiki_wikis = {
{ name = 'Personal', root = '/tmp/nuwiki-a' },
{ name = 'Work', root = '/tmp/nuwiki-b', file_extension = 'md' },
}
local list = require('nuwiki.config').wiki_list()
vim.g.nuwiki_wikis = nil
if #list ~= 2 then error('want 2 wikis, got ' .. #list) end
if list[1].name ~= 'Personal' or list[2].name ~= 'Work' then
error('names/order broken: ' .. vim.inspect(list))
end
if list[2].ext ~= '.md' then
error('per-wiki extension not honoured: ' .. tostring(list[2].ext))
end
end)
-- ===== Wrap up =====
table.insert(out_lines, '')