1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-24 10:47:07 +08:00

feat(git): lua completion for sub command

This commit is contained in:
Eric Wong 2024-12-17 17:50:28 +08:00
parent 3ffa25addc
commit bde1252f93
6 changed files with 167 additions and 109 deletions

View File

@ -1,3 +1,16 @@
"=============================================================================
" reset.vim --- git reset command
" Copyright (c) 2016-2019 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
if has('nvim-0.9.0')
function! git#reset#complete(ArgLead, CmdLine, CursorPos) abort
return luaeval('require("git.command.reset").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
endfunction
else
let s:JOB = SpaceVim#api#import('job') let s:JOB = SpaceVim#api#import('job')
@ -34,4 +47,4 @@ function! git#reset#complete(ArgLead, CmdLine, CursorPos)
return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n") return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n")
endfunction endfunction
endif

View File

@ -7,6 +7,11 @@
" :Git rm % " :Git rm %
" < " <
if has('nvim-0.9.0')
function! git#rm#complete(ArgLead, CmdLine, CursorPos) abort
return luaeval('require("git.command.rm").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
endfunction
else
let s:JOB = SpaceVim#api#import('job') let s:JOB = SpaceVim#api#import('job')
function! git#rm#run(files) abort function! git#rm#run(files) abort
@ -42,3 +47,4 @@ function! git#rm#complete(ArgLead, CmdLine, CursorPos) abort
return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n") return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n")
endfunction endfunction
endif

View File

@ -6,6 +6,11 @@
" :Git stash list " :Git stash list
" < " <
if has('nvim-0.9.0')
function! git#stash#complete(ArgLead, CmdLine, CursorPos) abort
return luaeval('require("git.command.stash").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
endfunction
else
let s:JOB = SpaceVim#api#import('job') let s:JOB = SpaceVim#api#import('job')
let s:NOTI = SpaceVim#api#import('notify') let s:NOTI = SpaceVim#api#import('notify')
let s:BUFFER = SpaceVim#api#import('vim#buffer') let s:BUFFER = SpaceVim#api#import('vim#buffer')
@ -141,3 +146,4 @@ function! git#stash#complete(ArgLead, CmdLine, CursorPos) abort
endfunction endfunction
endif

View File

@ -5,7 +5,7 @@
-- URL: https://spacevim.org -- URL: https://spacevim.org
-- License: GPLv3 -- License: GPLv3
--============================================================================= --=============================================================================
local m = {} local M = {}
local job = require('spacevim.api.job') local job = require('spacevim.api.job')
local nt = require('spacevim.api.notify') local nt = require('spacevim.api.notify')
@ -23,7 +23,7 @@ local function on_exit(id, code, single)
end end
end end
function m.run(argv) function M.run(argv)
local cmd = { 'git', 'reset' } local cmd = { 'git', 'reset' }
if #argv == 1 and argv[1] == '%' then if #argv == 1 and argv[1] == '%' then
cmd = { 'git', 'reset', 'HEAD', vim.fn.expand('%') } cmd = { 'git', 'reset', 'HEAD', vim.fn.expand('%') }
@ -38,4 +38,9 @@ function m.run(argv)
}) })
end end
return m function M.complete(ArgLead, CmdLine, CursorPos)
local rst = vim.fn.getcompletion(ArgLead, 'file')
return table.concat(rst, '\n')
end
return M

View File

@ -47,4 +47,9 @@ function m.run(argv)
}) })
end end
function M.complete(ArgLead, CmdLine, CursorPos)
local rst = vim.fn.getcompletion(ArgLead, 'file')
return table.concat(rst, '\n')
end
return m return m

View File

@ -97,4 +97,27 @@ function M.run(argv)
end end
end end
local function sub_commands()
return {
'list',
'show',
'drop',
'pop',
'apply',
'branch',
'clear',
'save',
'push',
}
end
function M.complete(ArgLead, CmdLine, CursorPos)
local str = string.sub(CmdLine, 1, CursorPos)
if vim.regex([[^Git\s\+stash\s\+[a-z]\+$]]):match_str(str) then
return table.concat(sub_commands(), '\n')
else
return ''
end
end
return M return M