Compare commits
No commits in common. "1eed1798f7025f37adc986b5128476c6599dc7da" and "e62f2f818ccbb33b646156d8261d8aed3f86311b" have entirely different histories.
1eed1798f7
...
e62f2f818c
4 changed files with 8 additions and 106 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
local config = require('pending.config')
|
local config = require('pending.config')
|
||||||
local forge = require('pending.forge')
|
|
||||||
|
|
||||||
---@class pending.CompletionItem
|
---@class pending.CompletionItem
|
||||||
---@field word string
|
---@field word string
|
||||||
|
|
@ -110,17 +109,6 @@ local function recur_completions()
|
||||||
return result
|
return result
|
||||||
end
|
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?
|
---@type string?
|
||||||
local _complete_source = nil
|
local _complete_source = nil
|
||||||
|
|
||||||
|
|
@ -140,10 +128,10 @@ function M.omnifunc(findstart, base)
|
||||||
{ vim.pesc(dk) .. ':([%S]*)$', dk },
|
{ vim.pesc(dk) .. ':([%S]*)$', dk },
|
||||||
{ 'cat:([%S]*)$', 'cat' },
|
{ 'cat:([%S]*)$', 'cat' },
|
||||||
{ vim.pesc(rk) .. ':([%S]*)$', rk },
|
{ 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
|
for _, check in ipairs(checks) do
|
||||||
local start = before:find(check[1])
|
local start = before:find(check[1])
|
||||||
|
|
@ -184,7 +172,7 @@ function M.omnifunc(findstart, base)
|
||||||
table.insert(matches, { word = c.word, menu = '[' .. source .. ']', info = c.info })
|
table.insert(matches, { word = c.word, menu = '[' .. source .. ']', info = c.info })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif M._is_forge_source(source) then
|
elseif source == 'gh' or source == 'gl' or source == 'cb' then
|
||||||
local s = require('pending.buffer').store()
|
local s = require('pending.buffer').store()
|
||||||
if s then
|
if s then
|
||||||
local seen = {}
|
local seen = {}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@
|
||||||
---@field icon? string
|
---@field icon? string
|
||||||
---@field issue_format? string
|
---@field issue_format? string
|
||||||
---@field instances? string[]
|
---@field instances? string[]
|
||||||
---@field shorthand? string
|
|
||||||
|
|
||||||
---@class pending.ForgeConfig
|
---@class pending.ForgeConfig
|
||||||
---@field auto_close? boolean
|
---@field auto_close? boolean
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,6 @@ function M.backends()
|
||||||
return _backends
|
return _backends
|
||||||
end
|
end
|
||||||
|
|
||||||
function M._reset_instances()
|
|
||||||
_instances_resolved = false
|
|
||||||
_by_shorthand = {}
|
|
||||||
for _, b in ipairs(_backends) do
|
|
||||||
_by_shorthand[b.shorthand] = b
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function _ensure_instances()
|
local function _ensure_instances()
|
||||||
if _instances_resolved then
|
if _instances_resolved then
|
||||||
return
|
return
|
||||||
|
|
@ -81,27 +73,17 @@ local function _ensure_instances()
|
||||||
for _, inst in ipairs(forge_cfg.instances or {}) do
|
for _, inst in ipairs(forge_cfg.instances or {}) do
|
||||||
_by_host[inst] = backend
|
_by_host[inst] = backend
|
||||||
end
|
end
|
||||||
if forge_cfg.shorthand and forge_cfg.shorthand ~= backend.shorthand then
|
|
||||||
_by_shorthand[backend.shorthand] = nil
|
|
||||||
backend.shorthand = forge_cfg.shorthand
|
|
||||||
_by_shorthand[backend.shorthand] = backend
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param token string
|
---@param token string
|
||||||
---@return pending.ForgeRef?
|
---@return pending.ForgeRef?
|
||||||
function M._parse_shorthand(token)
|
function M._parse_shorthand(token)
|
||||||
_ensure_instances()
|
local prefix, rest = token:match('^(%l%l):(.+)$')
|
||||||
local backend, rest
|
if not prefix then
|
||||||
for prefix, b in pairs(_by_shorthand) do
|
return nil
|
||||||
local candidate = token:match('^' .. vim.pesc(prefix) .. ':(.+)$')
|
|
||||||
if candidate then
|
|
||||||
backend = b
|
|
||||||
rest = candidate
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
local backend = _by_shorthand[prefix]
|
||||||
if not backend then
|
if not backend then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -391,73 +391,6 @@ describe('forge registry', function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('custom forge prefixes', function()
|
|
||||||
local config = require('pending.config')
|
|
||||||
local complete = require('pending.complete')
|
|
||||||
|
|
||||||
it('parses custom-length shorthand (3+ chars)', function()
|
|
||||||
local custom = forge.gitea_backend({
|
|
||||||
name = 'customforge',
|
|
||||||
shorthand = 'cgf',
|
|
||||||
default_host = 'custom.example.com',
|
|
||||||
})
|
|
||||||
forge.register(custom)
|
|
||||||
|
|
||||||
local ref = forge._parse_shorthand('cgf:alice/proj#99')
|
|
||||||
assert.is_not_nil(ref)
|
|
||||||
assert.equals('customforge', ref.forge)
|
|
||||||
assert.equals('alice', ref.owner)
|
|
||||||
assert.equals('proj', ref.repo)
|
|
||||||
assert.equals(99, ref.number)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('parse_ref dispatches custom-length shorthand', function()
|
|
||||||
local ref = forge.parse_ref('cgf:alice/proj#5')
|
|
||||||
assert.is_not_nil(ref)
|
|
||||||
assert.equals('customforge', ref.forge)
|
|
||||||
assert.equals(5, ref.number)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('find_refs finds custom-length shorthand', function()
|
|
||||||
local refs = forge.find_refs('Fix cgf:alice/proj#12')
|
|
||||||
assert.equals(1, #refs)
|
|
||||||
assert.equals('customforge', refs[1].ref.forge)
|
|
||||||
assert.equals(12, refs[1].ref.number)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('completion returns entries for custom backends', function()
|
|
||||||
assert.is_true(complete._is_forge_source('cgf'))
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('config shorthand override re-registers backend', function()
|
|
||||||
vim.g.pending = {
|
|
||||||
forge = {
|
|
||||||
github = { shorthand = 'github' },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
config.reset()
|
|
||||||
forge._reset_instances()
|
|
||||||
|
|
||||||
local ref = forge._parse_shorthand('github:user/repo#1')
|
|
||||||
assert.is_not_nil(ref)
|
|
||||||
assert.equals('github', ref.forge)
|
|
||||||
assert.equals('user', ref.owner)
|
|
||||||
assert.equals('repo', ref.repo)
|
|
||||||
assert.equals(1, ref.number)
|
|
||||||
|
|
||||||
assert.is_nil(forge._parse_shorthand('gh:user/repo#1'))
|
|
||||||
|
|
||||||
vim.g.pending = nil
|
|
||||||
config.reset()
|
|
||||||
for _, b in ipairs(forge.backends()) do
|
|
||||||
if b.name == 'github' then
|
|
||||||
b.shorthand = 'gh'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
forge._reset_instances()
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
||||||
describe('forge diff integration', function()
|
describe('forge diff integration', function()
|
||||||
local store = require('pending.store')
|
local store = require('pending.store')
|
||||||
local diff = require('pending.diff')
|
local diff = require('pending.diff')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue