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
+36 -18
View File
@@ -119,33 +119,29 @@ function! nuwiki#commands#wiki_index(count) abort
\ function('s:open_uri_from'))
endfunction
" Vim equivalent of the Lua `wiki_ui_select` — receives the list, asks
" via `inputlist()` (no `vim.ui.select` on plain Vim), then opens.
" `:VimwikiUISelect` — pick a wiki from the configured list and open its
" index. The list is read straight from config (see wiki_list below), not
" from the server, so the picker works from any buffer before a wiki file is
" ever opened — opening the chosen index then auto-starts the LSP via the
" FileType autocmd. Plain Vim has no `vim.ui.select`, so use `inputlist()`.
function! nuwiki#commands#wiki_ui_select() abort
call s:exec('nuwiki.wiki.select', [{}],
\ function('s:wiki_pick'))
endfunction
function! s:wiki_pick(notification) abort
let l:rows = get(get(a:notification, 'response', {}), 'result', [])
if type(l:rows) != type([]) || empty(l:rows)
echom 'nuwiki: no wikis configured'
let l:wikis = nuwiki#commands#wiki_list()
if empty(l:wikis)
echohl WarningMsg | echom 'nuwiki: no wikis configured' | echohl None
return
endif
let l:prompt = ['Pick a wiki:']
let l:prompt = ['Select a wiki:']
let l:i = 0
for l:w in l:rows
for l:w in l:wikis
let l:i += 1
call add(l:prompt, l:i . '. ' . get(l:w, 'name', '?')
\ . ' (' . get(l:w, 'root', '?') . ')')
call add(l:prompt, printf('%d. %s (%s)', l:i, l:w.name, l:w.root))
endfor
let l:choice = inputlist(l:prompt)
if l:choice < 1 || l:choice > len(l:rows)
if l:choice < 1 || l:choice > len(l:wikis)
return
endif
let l:wiki_id = get(l:rows[l:choice - 1], 'id', l:choice - 1)
call s:exec('nuwiki.wiki.openIndex', [{ 'wiki': l:wiki_id }],
\ function('s:open_uri_from'))
let l:w = l:wikis[l:choice - 1]
execute 'edit ' . fnameescape(l:w.root . '/' . l:w.idx . l:w.ext)
endfunction
" `:VimwikiNextLink` / `:VimwikiPrevLink` — pure-VimL `[[…]]` jumper.
@@ -427,6 +423,28 @@ function! s:wiki_cfg(n) abort
\ 'diary_rel': l:diary_rel, 'diary_idx': l:diary_idx }
endfunction
" Build the list of configured wikis as {name, root, ext, idx, diary_rel,
" diary_idx} dicts, straight from config — no LSP round-trip. Drives the wiki
" picker so it works before any wiki buffer (and therefore the server) exists.
" Falls back to a single entry from the scalar `g:nuwiki_wiki_root` config.
function! nuwiki#commands#wiki_list() abort
let l:list = []
if exists('g:nuwiki_wikis') && !empty(g:nuwiki_wikis)
let l:n = 0
for l:w in g:nuwiki_wikis
let l:c = s:wiki_cfg(l:n)
let l:c['name'] = get(l:w, 'name', fnamemodify(l:c.root, ':t'))
call add(l:list, l:c)
let l:n += 1
endfor
else
let l:c = s:wiki_cfg(0)
let l:c['name'] = fnamemodify(l:c.root, ':t')
call add(l:list, l:c)
endif
return l:list
endfunction
function! nuwiki#commands#open_wiki_path(tab) abort
let l:c = s:wiki_cfg(0)
execute (a:tab ? 'tabedit' : 'edit') . ' '