feat(forge): support custom shorthand prefixes

Problem: forge shorthand parsing hardcoded `%l%l` (exactly 2 lowercase
letters), preventing custom prefixes like `github:`. Completions also
hardcoded `gh:`, `gl:`, `cb:` patterns.

Solution: iterate `_by_shorthand` keys dynamically in `_parse_shorthand`
instead of matching a fixed pattern. Build completion patterns from
`forge.backends()`. Add `shorthand` field to `ForgeInstanceConfig` so
users can override prefixes via config, applied in `_ensure_instances()`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Barrett Ruth 2026-03-10 22:20:27 -04:00
parent e62f2f818c
commit 61eadec87e
4 changed files with 106 additions and 8 deletions

View file

@ -1,4 +1,5 @@
local config = require('pending.config')
local forge = require('pending.forge')
---@class pending.CompletionItem
---@field word string
@ -109,6 +110,17 @@ local function recur_completions()
return result
end
---@param source string
---@return boolean
function M._is_forge_source(source)
for _, b in ipairs(forge.backends()) do
if b.shorthand == source then
return true
end
end
return false
end
---@type string?
local _complete_source = nil
@ -128,10 +140,10 @@ function M.omnifunc(findstart, base)
{ vim.pesc(dk) .. ':([%S]*)$', dk },
{ 'cat:([%S]*)$', 'cat' },
{ vim.pesc(rk) .. ':([%S]*)$', rk },
{ 'gh:([%S]*)$', 'gh' },
{ 'gl:([%S]*)$', 'gl' },
{ 'cb:([%S]*)$', 'cb' },
}
for _, b in ipairs(forge.backends()) do
table.insert(checks, { vim.pesc(b.shorthand) .. ':([%S]*)$', b.shorthand })
end
for _, check in ipairs(checks) do
local start = before:find(check[1])
@ -172,7 +184,7 @@ function M.omnifunc(findstart, base)
table.insert(matches, { word = c.word, menu = '[' .. source .. ']', info = c.info })
end
end
elseif source == 'gh' or source == 'gl' or source == 'cb' then
elseif M._is_forge_source(source) then
local s = require('pending.buffer').store()
if s then
local seen = {}