hephaestus/heph.nvim/lua/heph/picker.lua
Erich Blume 7c9a734ebd
Some checks failed
Build / validate (pull_request) Failing after 2s
heph.nvim: task views — next/list/capture/attention/state/log (slice 11b)
Backend: enrich `list` to return titled RankedTask rows (title +
canonical_context_id, via a shared ranked_from_row with `next`), so the
Organizational view needs no N+1 node.get. TDD: query_surface test asserts
list rows carry title + context id.

Plugin:
- view.lua: Tactical `next` + Organizational `list` rendered scratch buffers;
  <CR> opens the row's canonical-context doc. Narrowed the node autocmd to
  heph://node/* so view buffers (heph://next, heph://list) don't trip it.
- task.lua: capture, set-attention, done/drop, skip, per-task log append, all
  resolving "the current task" from the buffer (a task node, or a context doc
  via its canonical-context backlink).
- picker.lua: vim.ui.select with Telescope auto-upgrade (headless-safe).
- command.lua: :Heph next/list/capture/attention/done/drop/skip/log/search.

e2e: capture→next→open context→add/check checklist→done; recurring
fresh-checklist (complete rolls forward in place, next occurrence all-unchecked
— the §4.4 hard requirement). 6 specs green via `mise run test-nvim`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-01 21:12:56 -07:00

56 lines
1.9 KiB
Lua

--- A single selection primitive. Uses built-in `vim.ui.select` so headless e2e
--- needs no plugins; auto-upgrades to Telescope when it is installed and not
--- explicitly disabled. Tests set `vim.g.heph_force_ui_select` and stub
--- `vim.ui.select`, so a picker never blocks in `--headless`.
local M = {}
local function telescope_available()
return pcall(require, "telescope")
end
--- Select one of `items`. `opts.prompt`, `opts.format(item)->string`.
--- `on_choice(item|nil, index|nil)` — nil when cancelled.
function M.select(items, opts, on_choice)
opts = opts or {}
if not vim.g.heph_force_ui_select and telescope_available() then
-- Telescope path: a thin wrapper so fuzzy UX is available when present.
-- (The dropdown is intentionally minimal; richer pickers can come later.)
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
pickers
.new({}, {
prompt_title = opts.prompt or "heph",
finder = finders.new_table({
results = items,
entry_maker = function(item)
local display = opts.format and opts.format(item) or tostring(item)
return { value = item, display = display, ordinal = display }
end,
}),
sorter = conf.generic_sorter({}),
attach_mappings = function(bufnr)
actions.select_default:replace(function()
actions.close(bufnr)
local sel = action_state.get_selected_entry()
on_choice(sel and sel.value or nil)
end)
return true
end,
})
:find()
return
end
vim.ui.select(items, {
prompt = opts.prompt,
format_item = opts.format,
}, function(choice, idx)
on_choice(choice, idx)
end)
end
return M