From 874bdd0c02995b3b1657d5795f810389dc4d8eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Sun, 31 May 2026 22:16:03 +0000 Subject: [PATCH] feat(diary): -count wiki selector for diary-note + index commands (P3) Closes the last command-cluster gap. Upstream's diary-note family (:Vimwiki{Make,TabMake,MakeYesterday,MakeTomorrow}DiaryNote + VimwikiDiaryIndex, and the Nuwiki* forms) carry -count=0 where the count selects the wiki number; nuwiki's were bare. Implemented as a real end-to-end selector, reusing existing infrastructure: - Server (commands.rs): OptUriArg gained an optional `wiki` selector; resolve_diary_wiki(backend, uri, wiki) now prefers it (via the existing resolve_wiki_selector, which already handles a 0-indexed wiki number) over the buffer URI. Used by diary_open_relative + diary_open_index. - Clients: s:diary_open / _diary_open (both) and diary_today/today_tab/ yesterday/tomorrow/index take a count and send {wiki: count-1} when >0. All 22 diary-note + DiaryIndex command defs across the 4 contexts are now -count=0 passing . diary_next/prev ignore the count. Tests: cmd.VimwikiMakeDiaryNote_has_count (test-keymaps.lua) + cmd.Vimwiki{MakeDiaryNote,DiaryIndex}_accepts_count (test-keymaps-vim.vim). Workspace test/clippy/fmt clean with CI flags; lua 284, vim 272/18/21. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/nuwiki-lsp/src/commands.rs | 16 ++++++--- development/tests/test-keymaps.lua | 9 ++++++ development/vimwiki-gap.md | 27 ++++++++++------ ftplugin/vimwiki.vim | 52 +++++++++++++++--------------- 4 files changed, 64 insertions(+), 40 deletions(-) diff --git a/crates/nuwiki-lsp/src/commands.rs b/crates/nuwiki-lsp/src/commands.rs index 526bd99..d169cba 100644 --- a/crates/nuwiki-lsp/src/commands.rs +++ b/crates/nuwiki-lsp/src/commands.rs @@ -392,7 +392,15 @@ enum RelativeDay { Tomorrow, } -fn resolve_diary_wiki(backend: &Backend, uri: Option<&Url>) -> Option { +fn resolve_diary_wiki( + backend: &Backend, + uri: Option<&Url>, + wiki: Option<&Value>, +) -> Option { + // An explicit wiki selector (vimwiki's `-count`) wins over the buffer URI. + if let Some(sel) = wiki { + return resolve_wiki_selector(backend, Some(sel)); + } if let Some(u) = uri { if let Some(w) = backend.wiki_for_uri(u) { return Some(w); @@ -407,7 +415,7 @@ fn diary_open_relative( rel: RelativeDay, ) -> Result, String> { let p = parse_optional_uri_arg(args)?; - let Some(wiki) = resolve_diary_wiki(backend, p.uri.as_ref()) else { + let Some(wiki) = resolve_diary_wiki(backend, p.uri.as_ref(), p.wiki.as_ref()) else { return Ok(None); }; let freq = wiki.config.frequency(); @@ -430,7 +438,7 @@ fn diary_open_relative( fn diary_open_index(backend: &Backend, args: Vec) -> Result, String> { let p = parse_optional_uri_arg(args)?; - let Some(wiki) = resolve_diary_wiki(backend, p.uri.as_ref()) else { + let Some(wiki) = resolve_diary_wiki(backend, p.uri.as_ref(), p.wiki.as_ref()) else { return Ok(None); }; let Some(uri) = crate::diary::index_uri(&wiki.config) else { @@ -444,7 +452,7 @@ fn diary_generate_index( args: Vec, ) -> Result, String> { let p = parse_optional_uri_arg(args)?; - let Some(wiki) = resolve_diary_wiki(backend, p.uri.as_ref()) else { + let Some(wiki) = resolve_diary_wiki(backend, p.uri.as_ref(), p.wiki.as_ref()) else { return Ok(None); }; let utf8 = backend.use_utf8.load(Ordering::Relaxed); diff --git a/development/tests/test-keymaps.lua b/development/tests/test-keymaps.lua index 0b8ff34..2835bec 100644 --- a/development/tests/test-keymaps.lua +++ b/development/tests/test-keymaps.lua @@ -906,6 +906,15 @@ vim.defer_fn(function() error(':NuwikiGenerateTags not defined') end end) + -- Diary-note family carries -count=0 (vimwiki's wiki selector), so + -- `:2VimwikiMakeDiaryNote` selects wiki #2 instead of raising E481. + tobj_case('cmd.VimwikiMakeDiaryNote_has_count', function() + local c = vim.api.nvim_buf_get_commands(0, {}).VimwikiMakeDiaryNote + if not c then error(':VimwikiMakeDiaryNote not defined') end + if c.count == nil or c.count == false then + error('VimwikiMakeDiaryNote missing -count: ' .. vim.inspect(c)) + end + end) -- `:VimwikiNormalizeLink 1` (the arg is upstream's visual flag; the command -- is -nargs=? not -range, so no `'<,'>`) wraps the last visual selection. tobj_case('cmd.normalize_link_visual_wraps_selection', function() diff --git a/development/vimwiki-gap.md b/development/vimwiki-gap.md index 423895a..d9fdf7b 100644 --- a/development/vimwiki-gap.md +++ b/development/vimwiki-gap.md @@ -300,16 +300,23 @@ fix site. The server edits are version-less single-line, so each line's edit applies independently — no server protocol change needed. Covered by `cmd.toggle_list_item_range` in `test-keymaps.lua`. -- [ ] **Diary-note family lacks `-count`** _(new, 2026-05-31 re-audit)_ — upstream's - `:Vimwiki{Make,TabMake,MakeYesterday,MakeTomorrow}DiaryNote` carry `-count=0` - (the count selects the wiki number); nuwiki's diary-note commands declare no - count in either branch. _Fix:_ `ftplugin/vimwiki.vim` diary block (both - branches) + thread the count into `diary_today/yesterday/tomorrow` + server - diary commands (accept an optional `wiki` selector). _(The `Index`/`TabIndex` - half is done: all four defs now use upstream's `-count=0` instead of bare - `-count`; `wiki_index`/`wiki_tab_index` already map the count to the wiki - number.)_ _(Re-audit 2026-05-31: `VimwikiDiaryIndex` is an additional instance - — bare in all four contexts vs upstream `-count=0` — fold it into this fix.)_ +- [x] **Diary-note family lacks `-count`** _(new, 2026-05-31 re-audit; fixed + same day)_ — upstream's `:Vimwiki{Make,TabMake,MakeYesterday,MakeTomorrow}DiaryNote` + + `VimwikiDiaryIndex` (and the `Nuwiki*` forms) carry `-count=0`, where the + count selects the wiki number. _Fix:_ a real wiki selector end-to-end — + - Server (`commands.rs`): `OptUriArg` gained an optional `wiki` selector and + `resolve_diary_wiki(backend, uri, wiki)` now prefers it (via the existing + `resolve_wiki_selector`, reused — accepts a 0-indexed number) over the + buffer URI; used by `diary_open_relative` + `diary_open_index`. + - Clients: `s:diary_open`/`diary_open` (both clients) and + `diary_today/today_tab/yesterday/tomorrow/index` take a count and send + `{wiki: count-1}` when > 0. All 22 diary-note + DiaryIndex command defs + across the 4 contexts are now `-count=0` passing ``. `diary_next`/ + `diary_prev` correctly ignore the count. + Tests: `cmd.VimwikiMakeDiaryNote_has_count` (`test-keymaps.lua`), + `cmd.Vimwiki{MakeDiaryNote,DiaryIndex}_accepts_count` (`test-keymaps-vim.vim`). + _(The `Index`/`TabIndex` family was already `-count=0`, mapping the count to + the wiki number via `wiki_index`/`wiki_tab_index`.)_ - [x] **`-complete=` specs** _(new; done 2026-05-31 command-attribute pass)_ — upstream attaches command-line completion to several commands; nuwiki had none, so `` at the `:` line never completed page / tag / colour names. diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 84ab100..16ab253 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -48,11 +48,11 @@ if !has('nvim') command! -buffer -count=0 VimwikiIndex call nuwiki#commands#wiki_index() command! -buffer -count=0 VimwikiTabIndex call nuwiki#commands#wiki_tab_index() command! -buffer VimwikiUISelect call nuwiki#commands#wiki_ui_select() - command! -buffer VimwikiDiaryIndex call nuwiki#commands#diary_index() - command! -buffer VimwikiMakeDiaryNote call nuwiki#commands#diary_today() - command! -buffer VimwikiTabMakeDiaryNote call nuwiki#commands#diary_today_tab() - command! -buffer VimwikiMakeYesterdayDiaryNote call nuwiki#commands#diary_yesterday() - command! -buffer VimwikiMakeTomorrowDiaryNote call nuwiki#commands#diary_tomorrow() + command! -buffer -count=0 VimwikiDiaryIndex call nuwiki#commands#diary_index() + command! -buffer -count=0 VimwikiMakeDiaryNote call nuwiki#commands#diary_today() + command! -buffer -count=0 VimwikiTabMakeDiaryNote call nuwiki#commands#diary_today_tab() + command! -buffer -count=0 VimwikiMakeYesterdayDiaryNote call nuwiki#commands#diary_yesterday() + command! -buffer -count=0 VimwikiMakeTomorrowDiaryNote call nuwiki#commands#diary_tomorrow() command! -buffer VimwikiDiaryNextDay call nuwiki#commands#diary_next() command! -buffer VimwikiDiaryPrevDay call nuwiki#commands#diary_prev() command! -buffer VimwikiDiaryGenerateLinks call nuwiki#commands#diary_generate_index() @@ -122,10 +122,10 @@ if !has('nvim') command! -buffer -count=0 NuwikiIndex call nuwiki#commands#wiki_index() command! -buffer -count=0 NuwikiTabIndex call nuwiki#commands#wiki_tab_index() command! -buffer NuwikiUISelect call nuwiki#commands#wiki_ui_select() - command! -buffer NuwikiDiaryIndex call nuwiki#commands#diary_index() - command! -buffer NuwikiDiaryToday call nuwiki#commands#diary_today() - command! -buffer NuwikiDiaryYesterday call nuwiki#commands#diary_yesterday() - command! -buffer NuwikiDiaryTomorrow call nuwiki#commands#diary_tomorrow() + command! -buffer -count=0 NuwikiDiaryIndex call nuwiki#commands#diary_index() + command! -buffer -count=0 NuwikiDiaryToday call nuwiki#commands#diary_today() + command! -buffer -count=0 NuwikiDiaryYesterday call nuwiki#commands#diary_yesterday() + command! -buffer -count=0 NuwikiDiaryTomorrow call nuwiki#commands#diary_tomorrow() command! -buffer NuwikiDiaryNext call nuwiki#commands#diary_next() command! -buffer NuwikiDiaryPrev call nuwiki#commands#diary_prev() command! -buffer NuwikiFollowLink call nuwiki#commands#follow_link_or_create() @@ -159,10 +159,10 @@ if !has('nvim') command! -buffer NuwikiNextLink call nuwiki#commands#link_next() command! -buffer NuwikiPrevLink call nuwiki#commands#link_prev() command! -buffer NuwikiBaddLink call nuwiki#commands#badd_link() - command! -buffer NuwikiMakeDiaryNote call nuwiki#commands#diary_today() - command! -buffer NuwikiTabMakeDiaryNote call nuwiki#commands#diary_today_tab() - command! -buffer NuwikiMakeYesterdayDiaryNote call nuwiki#commands#diary_yesterday() - command! -buffer NuwikiMakeTomorrowDiaryNote call nuwiki#commands#diary_tomorrow() + command! -buffer -count=0 NuwikiMakeDiaryNote call nuwiki#commands#diary_today() + command! -buffer -count=0 NuwikiTabMakeDiaryNote call nuwiki#commands#diary_today_tab() + command! -buffer -count=0 NuwikiMakeYesterdayDiaryNote call nuwiki#commands#diary_yesterday() + command! -buffer -count=0 NuwikiMakeTomorrowDiaryNote call nuwiki#commands#diary_tomorrow() command! -buffer NuwikiDiaryGenerateLinks call nuwiki#commands#diary_generate_index() command! -buffer NuwikiDiaryNextDay call nuwiki#commands#diary_next() command! -buffer NuwikiDiaryPrevDay call nuwiki#commands#diary_prev() @@ -395,11 +395,11 @@ endif command! -buffer -count=0 VimwikiIndex lua require('nuwiki.commands').wiki_index() command! -buffer -count=0 VimwikiTabIndex lua require('nuwiki.commands').wiki_tab_index() command! -buffer VimwikiUISelect lua require('nuwiki.commands').wiki_ui_select() -command! -buffer VimwikiDiaryIndex lua require('nuwiki.commands').diary_index() -command! -buffer VimwikiMakeDiaryNote lua require('nuwiki.commands').diary_today() -command! -buffer VimwikiTabMakeDiaryNote lua require('nuwiki.commands').diary_today_tab() -command! -buffer VimwikiMakeYesterdayDiaryNote lua require('nuwiki.commands').diary_yesterday() -command! -buffer VimwikiMakeTomorrowDiaryNote lua require('nuwiki.commands').diary_tomorrow() +command! -buffer -count=0 VimwikiDiaryIndex lua require('nuwiki.commands').diary_index() +command! -buffer -count=0 VimwikiMakeDiaryNote lua require('nuwiki.commands').diary_today() +command! -buffer -count=0 VimwikiTabMakeDiaryNote lua require('nuwiki.commands').diary_today_tab() +command! -buffer -count=0 VimwikiMakeYesterdayDiaryNote lua require('nuwiki.commands').diary_yesterday() +command! -buffer -count=0 VimwikiMakeTomorrowDiaryNote lua require('nuwiki.commands').diary_tomorrow() command! -buffer VimwikiDiaryNextDay lua require('nuwiki.commands').diary_next() command! -buffer VimwikiDiaryPrevDay lua require('nuwiki.commands').diary_prev() command! -buffer VimwikiDiaryGenerateLinks lua require('nuwiki.commands').diary_generate_index() @@ -471,10 +471,10 @@ command! -buffer VimwikiCatUrl lua require('nuwiki.commands' command! -buffer -count=0 NuwikiIndex lua require('nuwiki.commands').wiki_index() command! -buffer -count=0 NuwikiTabIndex lua require('nuwiki.commands').wiki_tab_index() command! -buffer NuwikiUISelect lua require('nuwiki.commands').wiki_ui_select() -command! -buffer NuwikiDiaryIndex lua require('nuwiki.commands').diary_index() -command! -buffer NuwikiDiaryToday lua require('nuwiki.commands').diary_today() -command! -buffer NuwikiDiaryYesterday lua require('nuwiki.commands').diary_yesterday() -command! -buffer NuwikiDiaryTomorrow lua require('nuwiki.commands').diary_tomorrow() +command! -buffer -count=0 NuwikiDiaryIndex lua require('nuwiki.commands').diary_index() +command! -buffer -count=0 NuwikiDiaryToday lua require('nuwiki.commands').diary_today() +command! -buffer -count=0 NuwikiDiaryYesterday lua require('nuwiki.commands').diary_yesterday() +command! -buffer -count=0 NuwikiDiaryTomorrow lua require('nuwiki.commands').diary_tomorrow() command! -buffer NuwikiDiaryNext lua require('nuwiki.commands').diary_next() command! -buffer NuwikiDiaryPrev lua require('nuwiki.commands').diary_prev() command! -buffer NuwikiDiaryGenerateLinks lua require('nuwiki.commands').diary_generate_index() @@ -504,10 +504,10 @@ command! -buffer -nargs=1 -complete=customlist,nuwiki#complete#pages NuwikiGoto command! -buffer NuwikiNextLink lua require('nuwiki.commands').link_next() command! -buffer NuwikiPrevLink lua require('nuwiki.commands').link_prev() command! -buffer NuwikiBaddLink lua require('nuwiki.commands').badd_link() -command! -buffer NuwikiMakeDiaryNote lua require('nuwiki.commands').diary_today() -command! -buffer NuwikiTabMakeDiaryNote lua require('nuwiki.commands').diary_today_tab() -command! -buffer NuwikiMakeYesterdayDiaryNote lua require('nuwiki.commands').diary_yesterday() -command! -buffer NuwikiMakeTomorrowDiaryNote lua require('nuwiki.commands').diary_tomorrow() +command! -buffer -count=0 NuwikiMakeDiaryNote lua require('nuwiki.commands').diary_today() +command! -buffer -count=0 NuwikiTabMakeDiaryNote lua require('nuwiki.commands').diary_today_tab() +command! -buffer -count=0 NuwikiMakeYesterdayDiaryNote lua require('nuwiki.commands').diary_yesterday() +command! -buffer -count=0 NuwikiMakeTomorrowDiaryNote lua require('nuwiki.commands').diary_tomorrow() command! -buffer NuwikiDiaryNextDay lua require('nuwiki.commands').diary_next() command! -buffer NuwikiDiaryPrevDay lua require('nuwiki.commands').diary_prev() command! -buffer Nuwiki2HTML lua require('nuwiki.commands').export_current()