fix(parse): skip forge refs in right-to-left metadata scan (#142)

Problem: `parse.body()` scans tokens right-to-left and breaks on the
first non-metadata token. Forge refs like `gl:a/b#12` halted the scan,
preventing metadata tokens to their left (e.g. `due:tomorrow`) from
being parsed. Additionally, `diff.parse_buffer()` ignored
`metadata.priority` from `+!!` tokens and only used checkbox-derived
priority, and priority updates between two non-zero values were silently
skipped.

Solution: Recognize forge ref tokens via `forge.parse_ref()` during the
right-to-left scan and skip past them, re-appending them to the
description so `forge.find_refs()` still works. Prefer
`metadata.priority` over checkbox priority in `parse_buffer()`, and
simplify the priority update condition to catch all value changes.
This commit is contained in:
Barrett Ruth 2026-03-11 13:02:55 -04:00
parent d26bdcb3a8
commit 79343cac2e
4 changed files with 74 additions and 5 deletions

View file

@ -1,4 +1,5 @@
local config = require('pending.config')
local forge = require('pending.forge')
---@class pending.Metadata
---@field due? string
@ -543,6 +544,7 @@ function M.body(text)
local date_pattern_strict = '^' .. vim.pesc(dk) .. ':(%d%d%d%d%-%d%d%-%d%d[T%d:]*)$'
local date_pattern_any = '^' .. vim.pesc(dk) .. ':(.+)$'
local rec_pattern = '^' .. vim.pesc(rk) .. ':(%S+)$'
local forge_indices = {}
while i >= 1 do
local token = tokens[i]
@ -602,6 +604,9 @@ function M.body(text)
end
metadata.recur = raw_spec
i = i - 1
elseif forge.parse_ref(token) then
table.insert(forge_indices, i)
i = i - 1
else
break
end
@ -615,6 +620,9 @@ function M.body(text)
for j = 1, i do
table.insert(desc_tokens, tokens[j])
end
for fi = #forge_indices, 1, -1 do
table.insert(desc_tokens, tokens[forge_indices[fi]])
end
local description = table.concat(desc_tokens, ' ')
return description, metadata