refactor(sync): extract backend interface, adapt gcal module

Problem: :Pending sync hardcodes Google Calendar — M.sync() does
pcall(require, 'pending.sync.gcal') and calls gcal.sync() directly.
The config has a flat gcal field. This prevents adding new sync backends
without modifying init.lua.

Solution: Define a backend interface contract (name, auth, sync, health
fields), refactor :Pending sync to dispatch via require('pending.sync.'
.. backend_name), add sync table to config with legacy gcal migration,
rename gcal.authorize to gcal.auth, add gcal.health for checkhealth,
and add tab completion for backend names and actions.
This commit is contained in:
Barrett Ruth 2026-02-26 16:44:20 -05:00
parent 8d3d21b330
commit 7de9c23ec1
5 changed files with 85 additions and 18 deletions

View file

@ -2,6 +2,9 @@
---@field calendar? string
---@field credentials_path? string
---@class pending.SyncConfig
---@field gcal? pending.GcalConfig
---@class pending.Keymaps
---@field close? string|false
---@field toggle? string|false
@ -32,6 +35,7 @@
---@field drawer_height? integer
---@field debug? boolean
---@field keymaps pending.Keymaps
---@field sync? pending.SyncConfig
---@field gcal? pending.GcalConfig
---@class pending.config
@ -65,6 +69,7 @@ local defaults = {
next_task = ']t',
prev_task = '[t',
},
sync = {},
}
---@type pending.Config?
@ -77,6 +82,10 @@ function M.get()
end
local user = vim.g.pending or {}
_resolved = vim.tbl_deep_extend('force', defaults, user)
if _resolved.gcal and not (_resolved.sync and _resolved.sync.gcal) then
_resolved.sync = _resolved.sync or {}
_resolved.sync.gcal = _resolved.gcal
end
return _resolved
end