fix(init): edit recompute, filter predicates, sync action listing

Problem: `M.edit()` skipped `_recompute_counts()` after saving,
`compute_hidden_ids` lacked `done`/`pending` predicates, and
`run_sync` defaulted to `sync` instead of listing available actions.

Solution: Replace `s:save()` with `_save_and_notify()` in `M.edit()`,
add `done` and `pending` filter predicates, and list backend actions
when no action is specified.
This commit is contained in:
Barrett Ruth 2026-03-05 11:18:46 -05:00
parent 59d2950fda
commit ca61db7127

View file

@ -142,6 +142,16 @@ local function compute_hidden_ids(tasks, predicates)
visible = false
break
end
elseif pred == 'done' then
if task.status ~= 'done' then
visible = false
break
end
elseif pred == 'pending' then
if task.status ~= 'pending' then
visible = false
break
end
end
end
if not visible then
@ -536,12 +546,25 @@ end
---@param action? string
---@return nil
local function run_sync(backend_name, action)
action = (action and action ~= '') and action or 'sync'
local ok, backend = pcall(require, 'pending.sync.' .. backend_name)
if not ok then
vim.notify('Unknown sync backend: ' .. backend_name, vim.log.levels.ERROR)
return
end
if not action or action == '' then
local actions = {}
for k, v in pairs(backend) do
if type(v) == 'function' and k:sub(1, 1) ~= '_' then
table.insert(actions, k)
end
end
table.sort(actions)
vim.notify(
backend_name .. ' actions: ' .. table.concat(actions, ', '),
vim.log.levels.INFO
)
return
end
if type(backend[action]) ~= 'function' then
vim.notify(backend_name .. " backend has no '" .. action .. "' action", vim.log.levels.ERROR)
return
@ -804,7 +827,7 @@ function M.edit(id_str, rest)
s:update(id, updates)
s:save()
_save_and_notify()
local bufnr = buffer.bufnr()
if bufnr and vim.api.nvim_buf_is_valid(bufnr) then
@ -841,7 +864,7 @@ function M.command(args)
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
M.edit(id_str, edit_rest)
elseif SYNC_BACKEND_SET[cmd] then
local action = rest:match('^(%S+)') or 'sync'
local action = rest:match('^(%S+)')
run_sync(cmd, action)
elseif cmd == 'archive' then
local d = rest ~= '' and tonumber(rest) or nil