Skip to content

fix: make pickers work with async vim.ui.select - #60

Merged
cvigilv merged 2 commits into
mainfrom
fix/async-ui-select
Oct 13, 2026
Merged

cvigilv merged 2 commits into
mainfrom
fix/async-ui-select

Conversation

@cvigilv

@cvigilv cvigilv commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Summary

Template selection and :EsqueletoNew assumed vim.ui.select returns only
after the user answers, as the built-in inputlist() does. Asynchronous
implementations such as telescope-ui-select return right away, which broke
both.

Template selection (core.lua): the picker opened from a FileType
autocmd that runs inside filetype detection's vim._with context. When that
context restored the previous window, focus left the picker, so it stayed on
screen while keystrokes went to the file buffer. The picker now opens via
vim.schedule, and the chosen template is written into the buffer that
requested it.

:EsqueletoNew (excmd.lua): each answer was checked on the line after
its prompt, so with an asynchronous picker the command printed "Exiting
template creation!" immediately. Each question is now asked from the
previous answer's callback. This also fixes an E484 error when choosing
"empty buffer", which happened with any picker.

Testing

  • New specs in tests/select_spec.lua and tests/excmd_spec.lua stub
    vim.ui.select/vim.ui.input with prompts that return before and after
    the answer. Six of the seven fail on main; the remaining one
    (cancelling the first :EsqueletoNew prompt) passes on both.
    make test_local: 24 passed.
  • Checked by hand with telescope-ui-select: choosing a skeleton for a new
    file (via :e and at startup) and stepping through :EsqueletoNew.

🤖 Generated with Claude Code

`selecttemplate` can run from a FileType autocmd fired inside filetype
detection's `vim._with` context. That context restores the previous
window on return, which takes focus away from asynchronous
`vim.ui.select` implementations such as telescope-ui-select: the picker
stays on screen while keystrokes go to the file buffer.

Open the picker with `vim.schedule` so it runs after the context is
restored. Capture the requesting buffer and write the chosen template
into it with `nvim_buf_call`, so the write and wildcard expansion target
that buffer regardless of which buffer is current when the choice
arrives. If the buffer was closed in the meantime, warn and write
nothing.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
`create_template` checked each answer on the line after its
`vim.ui.select`/`vim.ui.input` call, which only works when the prompt
returns after the user answers. With asynchronous implementations such
as telescope-ui-select, the command printed "Exiting template creation!"
immediately and the open picker had no effect.

Each question is now asked from the previous answer's callback, and
cancelling any prompt stops without creating anything. The "current
buffer" source is copied with `writefile` from the originating buffer,
and the trigger default is read from that buffer. Choosing "empty
buffer" no longer fails with E484 on a temp file that was never
written. On success, the message points to the template directory
where the new buffer should be saved.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
@cvigilv
cvigilv merged commit 049a502 into main Oct 13, 2026
2 checks passed
@cvigilv
cvigilv deleted the fix/async-ui-select branch October 13, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant