fix(parse): position-independent inline metadata parsing (#164)
Some checks are pending
quality / changes (push) Waiting to run
quality / Lua Format Check (push) Blocked by required conditions
quality / Lua Lint Check (push) Blocked by required conditions
quality / Lua Type Check (push) Blocked by required conditions
quality / Markdown Format Check (push) Blocked by required conditions
test / Test (Neovim nightly) (push) Waiting to run
test / Test (Neovim stable) (push) Waiting to run

Problem: `parse.body()` scanned tokens right-to-left and broke on the
first non-metadata token, so metadata only worked at the trailing end
of a line. `due:tomorrow Fix the bug` silently failed to parse the
due date.

Solution: Replace the right-to-left `while` loop with a single
left-to-right pass that extracts metadata tokens from any position.
Duplicate metadata tokens are dropped with a `log.warn`. Update docs
and tests accordingly.
This commit is contained in:
Barrett Ruth 2026-03-13 20:48:18 -04:00
parent 6e220797b9
commit f3ef1ca0db
3 changed files with 33 additions and 3 deletions

View file

@ -1,5 +1,6 @@
local config = require('pending.config')
local forge = require('pending.forge')
local log = require('pending.log')
---@class pending.Metadata
---@field due? string
@ -553,6 +554,8 @@ function M.body(text)
if due_val and is_valid_datetime(due_val) then
if not metadata.due then
metadata.due = due_val
else
log.warn('duplicate ' .. dk .. ': token ignored: ' .. token)
end
consumed = true
end
@ -563,6 +566,8 @@ function M.body(text)
if resolved then
if not metadata.due then
metadata.due = resolved
else
log.warn('duplicate ' .. dk .. ': token ignored: ' .. token)
end
consumed = true
end
@ -574,6 +579,8 @@ function M.body(text)
if cat_val then
if not metadata.category then
metadata.category = cat_val
else
log.warn('duplicate ' .. ck .. ': token ignored: ' .. token)
end
consumed = true
end
@ -585,6 +592,8 @@ function M.body(text)
if not metadata.priority then
local max = config.get().max_priority or 3
metadata.priority = math.min(#pri_bangs, max)
else
log.warn('duplicate priority token ignored: ' .. token)
end
consumed = true
end
@ -602,6 +611,8 @@ function M.body(text)
if not metadata.recur then
metadata.recur_mode = rec_val:sub(1, 1) == '!' and 'completion' or nil
metadata.recur = raw_spec
else
log.warn('duplicate ' .. rk .. ': token ignored: ' .. token)
end
consumed = true
end