refactor: tighten LuaCATS annotations and canonicalize metadata fields (#141)

* refactor: tighten LuaCATS annotations across modules

Problem: type annotations repeated inline unions with no aliases,
used `table<string, any>` where structured types exist, and had
loose `string` where union types should be used.

Solution: add `pending.TaskStatus`, `pending.RecurMode`,
`pending.TaskExtra`, `pending.ForgeType`, `pending.ForgeState`,
`pending.ForgeAuthStatus` aliases and `pending.SyncBackend`
interface. Replace inline unions and loose types with the new
aliases in `store.lua`, `forge.lua`, `config.lua`, `diff.lua`,
`views.lua`, `parse.lua`, `init.lua`, and `oauth.lua`.

* refactor: canonicalize internal metadata field names

Problem: `pending.Metadata` used shorthand field names (`cat`, `rec`,
`rec_mode`) matching user-facing token syntax, coupling internal
representation to config. `RecurSpec.from_completion` used a boolean
where a `pending.RecurMode` alias exists. `category_syntax` was
hardcoded to `'cat'` with no config option.

Solution: rename `Metadata` fields to `category`/`recur`/`recur_mode`,
add `category_syntax` config option (default `'cat'`), rename
`ParsedEntry` fields to match, replace `RecurSpec.from_completion`
with `mode: pending.RecurMode`, and restore `[string]` indexer on
`pending.ForgeConfig` alongside explicit fields.
This commit is contained in:
Barrett Ruth 2026-03-11 12:55:36 -04:00 committed by GitHub
parent 287a4e32e3
commit b131d6d391
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 144 additions and 80 deletions

View file

@ -984,10 +984,10 @@ function M.add(text)
end
s:add({
description = description,
category = metadata.cat,
category = metadata.category,
due = metadata.due,
recur = metadata.rec,
recur_mode = metadata.rec_mode,
recur = metadata.recur,
recur_mode = metadata.recur_mode,
priority = metadata.priority,
})
_save_and_notify()
@ -998,6 +998,14 @@ function M.add(text)
log.info('Task added: ' .. description)
end
---@class pending.SyncBackend
---@field name string
---@field auth fun(): nil
---@field push? fun(): nil
---@field pull? fun(): nil
---@field sync? fun(): nil
---@field health? fun(): nil
---@type string[]?
local _sync_backends = nil
@ -1186,6 +1194,7 @@ end
local function parse_edit_token(token)
local recur = require('pending.recur')
local cfg = require('pending.config').get()
local ck = cfg.category_syntax or 'cat'
local dk = cfg.date_syntax or 'due'
local rk = cfg.recur_syntax or 'rec'
@ -1201,7 +1210,7 @@ local function parse_edit_token(token)
if token == '-due' or token == '-' .. dk then
return 'due', vim.NIL, nil
end
if token == '-cat' then
if token == '-' .. ck then
return 'category', vim.NIL, nil
end
if token == '-rec' or token == '-' .. rk then
@ -1223,7 +1232,7 @@ local function parse_edit_token(token)
'Invalid date: ' .. due_val .. '. Use YYYY-MM-DD, today, tomorrow, +Nd, weekday names, etc.'
end
local cat_val = token:match('^cat:(.+)$')
local cat_val = token:match('^' .. vim.pesc(ck) .. ':(.+)$')
if cat_val then
return 'category', cat_val, nil
end
@ -1248,11 +1257,15 @@ local function parse_edit_token(token)
.. token
.. '. Valid: '
.. dk
.. ':<date>, cat:<name>, '
.. ':<date>, '
.. ck
.. ':<name>, '
.. rk
.. ':<pattern>, +!, -!, -'
.. dk
.. ', -cat, -'
.. ', -'
.. ck
.. ', -'
.. rk
end