1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-14 15:19:12 +08:00

feat(git): implement lua complete for git-add

This commit is contained in:
Eric Wong 2024-12-17 08:52:48 +08:00
parent 64438a033e
commit 700aee7395
2 changed files with 44 additions and 32 deletions

View File

@ -7,46 +7,52 @@
" :Git add %
" <
let s:JOB = SpaceVim#api#import('job')
let s:NOTI = SpaceVim#api#import('notify')
if has('nvim-0.9.0')
function! git#add#complete(ArgLead, CmdLine, CursorPos) abort
return luaeval('require("git.command.add").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:NOTI = SpaceVim#api#import('notify')
function! s:replace_argvs(argvs) abort
let argvs = []
for argv in a:argvs
if argv ==# '%'
call insert(argvs, expand('%'))
else
call insert(argvs, argv)
endif
endfor
return argvs
endfunction
function! s:replace_argvs(argvs) abort
let argvs = []
for argv in a:argvs
if argv ==# '%'
call insert(argvs, expand('%'))
else
call insert(argvs, argv)
endif
endfor
return argvs
endfunction
function! git#add#run(argvs) abort
let cmd = ['git', 'add'] + s:replace_argvs(a:argvs)
call git#logger#debug('git-add cmd:' . string(cmd))
call s:JOB.start(cmd,
\ {
function! git#add#run(argvs) abort
let cmd = ['git', 'add'] + s:replace_argvs(a:argvs)
call git#logger#debug('git-add cmd:' . string(cmd))
call s:JOB.start(cmd,
\ {
\ 'on_exit' : function('s:on_exit'),
\ }
\ )
endfunction
endfunction
function! s:on_exit(id, data, event) abort
call git#logger#debug('git-add exit data:' . string(a:data))
if a:data ==# 0
if exists(':GitGutter')
GitGutter
function! s:on_exit(id, data, event) abort
call git#logger#debug('git-add exit data:' . string(a:data))
if a:data ==# 0
if exists(':GitGutter')
GitGutter
endif
call s:NOTI.notify('stage files done!')
else
call s:NOTI.notify('stage files failed!')
endif
call s:NOTI.notify('stage files done!')
else
call s:NOTI.notify('stage files failed!')
endif
endfunction
endfunction
function! git#add#complete(ArgLead, CmdLine, CursorPos) abort
function! git#add#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

@ -39,4 +39,10 @@ function M.run(argv)
job.start(cmd, { on_exit = on_exit })
end
function M.complete(ArgLead, CmdLine, CursorPos)
local rst = vim.fn.getcompletion(ArgLead, 'file')
table.insert(rst, '%')
return table.concat(rst, '\n')
end
return M