feat(complete): add info descriptions to omnifunc items

Problem: completion menu items had no description, making it hard to
distinguish between similar entries like date shorthands and recurrence
patterns.

Solution: return { word, info } tables from date_completions() and
recur_completions(), surfacing human-readable descriptions in the
completion popup.
This commit is contained in:
Barrett Ruth 2026-02-25 20:34:56 -05:00
parent 66eb93a6d1
commit 18049e91a0

View file

@ -29,60 +29,75 @@ local function get_categories()
return result return result
end end
---@return string[] ---@return { word: string, info: string }[]
local function date_completions() local function date_completions()
return { return {
'today', { word = 'today', info = "Today's date" },
'tomorrow', { word = 'tomorrow', info = "Tomorrow's date" },
'yesterday', { word = 'yesterday', info = "Yesterday's date" },
'+1d', { word = '+1d', info = '1 day from today' },
'+2d', { word = '+2d', info = '2 days from today' },
'+3d', { word = '+3d', info = '3 days from today' },
'+1w', { word = '+1w', info = '1 week from today' },
'+2w', { word = '+2w', info = '2 weeks from today' },
'+1m', { word = '+1m', info = '1 month from today' },
'mon', { word = 'mon', info = 'Next Monday' },
'tue', { word = 'tue', info = 'Next Tuesday' },
'wed', { word = 'wed', info = 'Next Wednesday' },
'thu', { word = 'thu', info = 'Next Thursday' },
'fri', { word = 'fri', info = 'Next Friday' },
'sat', { word = 'sat', info = 'Next Saturday' },
'sun', { word = 'sun', info = 'Next Sunday' },
'eod', { word = 'eod', info = 'End of day (today)' },
'eow', { word = 'eow', info = 'End of week (Sunday)' },
'eom', { word = 'eom', info = 'End of month' },
'eoq', { word = 'eoq', info = 'End of quarter' },
'eoy', { word = 'eoy', info = 'End of year (Dec 31)' },
'sow', { word = 'sow', info = 'Start of week (Monday)' },
'som', { word = 'som', info = 'Start of month' },
'soq', { word = 'soq', info = 'Start of quarter' },
'soy', { word = 'soy', info = 'Start of year (Jan 1)' },
'later', { word = 'later', info = 'Someday (sentinel date)' },
'today@08:00', { word = 'today@08:00', info = 'Today at 08:00' },
'today@09:00', { word = 'today@09:00', info = 'Today at 09:00' },
'today@10:00', { word = 'today@10:00', info = 'Today at 10:00' },
'today@12:00', { word = 'today@12:00', info = 'Today at 12:00' },
'today@14:00', { word = 'today@14:00', info = 'Today at 14:00' },
'today@17:00', { word = 'today@17:00', info = 'Today at 17:00' },
'tomorrow@08:00',
'tomorrow@09:00',
'tomorrow@10:00',
'tomorrow@12:00',
'tomorrow@14:00',
'tomorrow@17:00',
} }
end end
---@return string[] ---@type table<string, string>
local recur_descriptions = {
daily = 'Every day',
weekdays = 'Monday through Friday',
weekly = 'Every week',
biweekly = 'Every 2 weeks',
monthly = 'Every month',
quarterly = 'Every 3 months',
yearly = 'Every year',
['2d'] = 'Every 2 days',
['3d'] = 'Every 3 days',
['2w'] = 'Every 2 weeks',
['3w'] = 'Every 3 weeks',
['2m'] = 'Every 2 months',
['3m'] = 'Every 3 months',
['6m'] = 'Every 6 months',
['2y'] = 'Every 2 years',
}
---@return { word: string, info: string }[]
local function recur_completions() local function recur_completions()
local recur = require('pending.recur') local recur = require('pending.recur')
local list = recur.shorthand_list() local list = recur.shorthand_list()
local result = {} local result = {}
for _, s in ipairs(list) do for _, s in ipairs(list) do
table.insert(result, s) local desc = recur_descriptions[s] or s
table.insert(result, { word = s, info = desc })
end end
for _, s in ipairs(list) do for _, s in ipairs(list) do
table.insert(result, '!' .. s) local desc = recur_descriptions[s] or s
table.insert(result, { word = '!' .. s, info = desc .. ' (from completion date)' })
end end
return result return result
end end
@ -123,24 +138,29 @@ function M.omnifunc(findstart, base)
return -1 return -1
end end
local candidates = {} local matches = {}
local source = _complete_source or '' local source = _complete_source or ''
local dk = date_key() local dk = date_key()
local rk = recur_key() local rk = recur_key()
if source == dk then if source == dk then
candidates = date_completions() for _, c in ipairs(date_completions()) do
if base == '' or c.word:sub(1, #base) == base then
table.insert(matches, { word = c.word, menu = '[' .. source .. ']', info = c.info })
end
end
elseif source == 'cat' then elseif source == 'cat' then
candidates = get_categories() for _, c in ipairs(get_categories()) do
if base == '' or c:sub(1, #base) == base then
table.insert(matches, { word = c, menu = '[cat]' })
end
end
elseif source == rk then elseif source == rk then
candidates = recur_completions() for _, c in ipairs(recur_completions()) do
end if base == '' or c.word:sub(1, #base) == base then
table.insert(matches, { word = c.word, menu = '[' .. source .. ']', info = c.info })
local matches = {} end
for _, c in ipairs(candidates) do
if base == '' or c:sub(1, #base) == base then
table.insert(matches, { word = c, menu = '[' .. source .. ']' })
end end
end end