fix(commands): route Neovim *Link Ex-commands through follow_link_or_create
CI / cargo fmt --check (push) Successful in 28s
CI / cargo clippy (push) Successful in 34s
CI / cargo test (push) Successful in 30s
CI / editor keymaps (push) Successful in 1m32s

Audit follow-up on the two link-path items flagged during the command-attribute
pass:

- REAL (bug #2): all eight Neovim Ex-command link defs (Vimwiki/Nuwiki ×
  FollowLink/SplitLink/VSplitLink/TabnewLink) dispatched to raw
  `lua vim.lsp.buf.definition()`, bypassing the bare-word → [[link]] wrap +
  create-on-follow that the Vim commands and the Neovim <CR> family already do.
  All eight now call follow_link_or_create() (keeping their split/vsplit/tabnew
  prefixes). TabDropLink already used follow_link_drop and is unchanged.

- FALSE ALARM (bug #1): the audit's claim that lua follow_link_or_create was
  "botched" (double definition() with dead pos_args code, no wrap) was a
  mis-read — it was a single correct definition that already wrapped bare words
  and is dispatched by <CR>. Tidied anyway: collapsed its two definition() call
  sites into one tail call; behaviour is identical (wrap still skipped when
  already inside a link, via short-circuit).

Tests: cmd.VimwikiFollowLink_wraps_bare_word + cmd.VimwikiSplitLink_wraps_bare_word
(test-keymaps.lua). Both harnesses green (lua 280, vim 269/18/21, 0 failed);
gap doc corrected for both entries.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 21:04:31 +00:00
parent 3b3d8ca782
commit 2b3bc48b75
3 changed files with 36 additions and 30 deletions
+5 -9
View File
@@ -237,17 +237,13 @@ function M.follow_link_drop()
end
function M.follow_link_or_create()
if cursor_inside_wikilink() then
vim.lsp.buf.definition()
-- Already on a wikilink → follow it. Otherwise try to wrap the bare word
-- under the cursor as `[[word]]` and stop (a second press follows it,
-- matching vimwiki's review-then-follow flow). If there's nothing to wrap,
-- fall through to a plain definition request so a chord still works anywhere.
if not cursor_inside_wikilink() and wrap_cword_as_wikilink() then
return
end
if wrap_cword_as_wikilink() then
-- Wrapped — leave the user inside the new `[[…]]` and stop. A
-- second `<CR>` follows it, matching vimwiki's review-then-follow
-- flow.
return
end
-- No word under cursor either — fall through.
vim.lsp.buf.definition()
end