feat(file-token): file: inline metadata token with gf navigation (#45)

* feat(file-token): add file: inline metadata token with gf navigation

Problem: there was no way to link a task to a specific location in a
source file, or to quickly jump from a task to the relevant code.

Solution: add a file:<path>:<line> inline token that stores a relative
file reference in task._extra.file. Virtual text renders basename:line
in a new PendingFile highlight group. A buffer-local gf mapping
(configurable via keymaps.goto_file) opens the file at the given line.
M.add_here() lets users attach the current cursor position to any task
via vim.ui.select(). M.edit() gains -file support to clear the
reference. <Plug>(pending-goto-file) and <Plug>(pending-add-here) are
exposed for custom mappings.

* test(file-token): add parse, diff, views, edit, and navigation tests

Problem: the file: token implementation had no test coverage.

Solution: add spec/file_spec.lua covering parse.body extraction,
malformed token handling, duplicate token stop-parsing, diff
reconciliation (store/update/clear/round-trip), LineMeta population
in both views, :Pending edit -file, and goto_file notify paths for
no-file and unreadable-file cases. All 292 tests pass.

* style: apply stylua formatting

* fix(types): remove empty elseif block, fix file? annotation nullability
This commit is contained in:
Barrett Ruth 2026-02-26 19:12:48 -05:00
parent de0dc564cf
commit a2e0e296ac
10 changed files with 605 additions and 8 deletions

View file

@ -12,6 +12,7 @@ local store = require('pending.store')
---@field due? string
---@field rec? string
---@field rec_mode? string
---@field file? string
---@field lnum integer
---@class pending.diff
@ -57,6 +58,7 @@ function M.parse_buffer(lines)
due = metadata.due,
rec = metadata.rec,
rec_mode = metadata.rec_mode,
file = metadata.file,
lnum = i,
})
end
@ -133,6 +135,19 @@ function M.apply(lines, hidden_ids)
task.recur_mode = entry.rec_mode
changed = true
end
local old_file = (task._extra and task._extra.file) or nil
if entry.file ~= old_file then
task._extra = task._extra or {}
if entry.file then
task._extra.file = entry.file
else
task._extra.file = nil
if next(task._extra) == nil then
task._extra = nil
end
end
changed = true
end
if entry.status and task.status ~= entry.status then
task.status = entry.status
if entry.status == 'done' then