mirror of
https://github.com/harivansh-afk/forge.nvim.git
synced 2026-04-15 08:03:44 +00:00
fix: cli completion
This commit is contained in:
parent
c0d2a19498
commit
b4db29e77a
1 changed files with 21 additions and 16 deletions
|
|
@ -442,7 +442,12 @@ local function dispatch(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function complete(arglead, cmdline, _)
|
local function complete(arglead, cmdline, _)
|
||||||
local parts = vim.split(vim.trim(cmdline), '%s+')
|
local words = {}
|
||||||
|
for word in cmdline:gmatch('%S+') do
|
||||||
|
table.insert(words, word)
|
||||||
|
end
|
||||||
|
local arg_idx = arglead == '' and #words or #words - 1
|
||||||
|
|
||||||
local subcmds =
|
local subcmds =
|
||||||
{ 'pr', 'issue', 'ci', 'commit', 'branch', 'worktree', 'browse', 'yank', 'review', 'cache' }
|
{ 'pr', 'issue', 'ci', 'commit', 'branch', 'worktree', 'browse', 'yank', 'review', 'cache' }
|
||||||
local sub_actions = {
|
local sub_actions = {
|
||||||
|
|
@ -469,26 +474,26 @@ local function complete(arglead, cmdline, _)
|
||||||
}
|
}
|
||||||
local create_flags = { '--draft', '--fill', '--web' }
|
local create_flags = { '--draft', '--fill', '--web' }
|
||||||
|
|
||||||
if #parts <= 2 then
|
local function filter(candidates)
|
||||||
return vim.tbl_filter(function(s)
|
|
||||||
return s:find(arglead, 1, true) == 1
|
|
||||||
end, subcmds)
|
|
||||||
end
|
|
||||||
local sub = parts[2]
|
|
||||||
if #parts == 3 or (#parts == 4 and sub == 'pr' and parts[3] == 'create') then
|
|
||||||
local candidates = sub_actions[sub] or {}
|
|
||||||
if sub == 'pr' and #parts >= 3 and parts[3] == 'create' then
|
|
||||||
candidates = create_flags
|
|
||||||
end
|
|
||||||
return vim.tbl_filter(function(s)
|
return vim.tbl_filter(function(s)
|
||||||
return s:find(arglead, 1, true) == 1
|
return s:find(arglead, 1, true) == 1
|
||||||
end, candidates)
|
end, candidates)
|
||||||
end
|
end
|
||||||
if sub == 'pr' and parts[3] == 'create' then
|
|
||||||
return vim.tbl_filter(function(s)
|
if arg_idx == 1 then
|
||||||
return s:find(arglead, 1, true) == 1
|
return filter(subcmds)
|
||||||
end, create_flags)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local sub = words[2]
|
||||||
|
|
||||||
|
if arg_idx == 2 then
|
||||||
|
return filter(sub_actions[sub] or {})
|
||||||
|
end
|
||||||
|
|
||||||
|
if sub == 'pr' and words[3] == 'create' then
|
||||||
|
return filter(create_flags)
|
||||||
|
end
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue