fix(finder): handle abort in mini.pick integration#1983
Merged
Conversation
`Finder:find` documents that `on_select` is invoked with the selected item or `nil` if aborted. Every integration honors this except `mini_pick`: `source.choose` only fires on explicit confirm (<CR>), and aborting via <Esc> goes through `picker_stop`, which never calls `choose`. Through `find_async = a.wrap(Finder.find, 2)`, callers using `open_async` (e.g. `bb` -> `checkout_branch_revision`) `coroutine.yield` waiting for `on_select` to resume them. When `on_select` never runs, the coroutine is suspended forever and the picker appears dead until Neovim is restarted. Wire a one-shot `MiniPickStop` autocmd (mini.pick has no `source.on_close` field) so an abort still completes the finder via `on_select(nil)`. The new `mini_pick_choose` helper mirrors `snacks_confirm`, including the `completed` guard that ensures `on_select` runs exactly once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
mini_pickis enabled as the finder integration, aborting a selection (e.g. pressing<Esc>in the branch picker opened viabb) leaves thefind_asynccoroutine suspended forever. The picker then appears dead — subsequentbbinvocations show nothing until Neovim is restarted.Root cause
Finder:finddocuments its contract as (finder.lua:307-308):---Engages finder and invokes `on_select` with the item or items, or nil if abortedEvery integration branch honors this —
on_select(nil)is called on abort — exceptmini_pick:mini.pick'ssource.chooseonly fires on explicit confirm (<CR>). Aborting via<Esc>goes throughpicker_stop, which never callschoose. As a resulton_selectis never invoked on abort.Since
Finder.find_async = a.wrap(Finder.find, 2), callers usingopen_async(e.g.checkout_branch_revisionviabb) `coroutine.yield` waiting foron_selectto resume them. Withon_selectnever firing, the coroutine is permanently suspended.Compare with how the other integrations handle abort:
on_select(nil)vim.ui.selecton_select(...)with a nil itemfzf_lua["esc"]/["ctrl-c"]/["ctrl-q"]→close_action→on_select(nil)telescopeon_select(nil)snackson_close→complete(nil)→on_select(nil)mini_pickFix
Wire a one-shot
MiniPickStopautocmd (mini.pick has nosource.on_closefield) so an abort still completes the finder viaon_select(nil). The newmini_pick_choosehelper mirrors the existingsnacks_confirm, including thecompletedguard that ensureson_selectruns exactly once.Reproduce
setup({ integrations = { mini_pick = true } })bb(branch/revision checkout)<Esc>instead of<CR>bbagain — picker no longer opens; requires restarting Neovim to recover