1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 21:20:05 +08:00

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

This commit is contained in:
Eric Wong 2024-12-17 17:30:08 +08:00
parent a0b86e67e8
commit 3ffa25addc
2 changed files with 85 additions and 72 deletions

View File

@ -6,88 +6,94 @@
" :Git tag --list " :Git tag --list
" < " <
let s:JOB = SpaceVim#api#import('job') if has('nvim-0.9.0')
let s:NT = SpaceVim#api#import('notify') function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort
let s:jobid = -1 return luaeval('require("git.command.tag").complete(vim.api.nvim_eval("a:ArgLead"), vim.api.nvim_eval("a:CmdLine"), vim.api.nvim_eval("a:CursorPos"))')
let s:stderr_data = [] endfunction
else
function! git#tag#run(argvs) abort let s:JOB = SpaceVim#api#import('job')
let s:NT = SpaceVim#api#import('notify')
if s:jobid != -1 let s:jobid = -1
call s:NT.notify('previous tag command is not finished')
return
endif
let s:NT.notify_max_width = float2nr(&columns * 0.3)
let s:stderr_data = [] let s:stderr_data = []
let cmd = ['git', 'tag'] + a:argvs function! git#tag#run(argvs) abort
call git#logger#debug('git-tag cmd:' . string(cmd))
let s:jobid = s:JOB.start(cmd,
\ {
\ 'on_stdout' : function('s:on_stdout'),
\ 'on_stderr' : function('s:on_stderr'),
\ 'on_exit' : function('s:on_exit'),
\ }
\ )
if s:jobid == -1 if s:jobid != -1
call s:NT.notify('`git` is not executable', 'WarningMsg') call s:NT.notify('previous tag command is not finished')
endif return
endif
endfunction let s:NT.notify_max_width = float2nr(&columns * 0.3)
function! s:on_stdout(id, data, event) abort let s:stderr_data = []
if a:id != s:jobid
return
endif
for line in a:data
call s:NT.notify(line)
endfor
endfunction
function! s:on_stderr(id, data, event) abort let cmd = ['git', 'tag'] + a:argvs
if a:id != s:jobid call git#logger#debug('git-tag cmd:' . string(cmd))
return let s:jobid = s:JOB.start(cmd,
endif \ {
for line in a:data \ 'on_stdout' : function('s:on_stdout'),
call add(s:stderr_data, line) \ 'on_stderr' : function('s:on_stderr'),
endfor \ 'on_exit' : function('s:on_exit'),
endfunction \ }
\ )
function! s:on_exit(id, data, event) abort if s:jobid == -1
call git#logger#debug('git-tag exit data:' . string(a:data)) call s:NT.notify('`git` is not executable', 'WarningMsg')
if a:id != s:jobid endif
return
endif endfunction
if a:data ==# 0
for line in s:stderr_data function! s:on_stdout(id, data, event) abort
if a:id != s:jobid
return
endif
for line in a:data
call s:NT.notify(line) call s:NT.notify(line)
endfor endfor
else endfunction
for line in s:stderr_data
call s:NT.notify(line, 'WarningMsg') function! s:on_stderr(id, data, event) abort
if a:id != s:jobid
return
endif
for line in a:data
call add(s:stderr_data, line)
endfor endfor
endif endfunction
let s:jobid = -1
endfunction
function! s:options() abort function! s:on_exit(id, data, event) abort
return [ call git#logger#debug('git-tag exit data:' . string(a:data))
\ '--list', if a:id != s:jobid
\ ] return
endfunction endif
if a:data ==# 0
for line in s:stderr_data
call s:NT.notify(line)
endfor
else
for line in s:stderr_data
call s:NT.notify(line, 'WarningMsg')
endfor
endif
let s:jobid = -1
endfunction
function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort function! s:options() abort
let str = a:CmdLine[:a:CursorPos-1] return [
if str =~# '^Git\s\+tag\s\+-$' \ '--list',
return join(s:options(), "\n") \ ]
elseif str =~# '^Git\s\+tag\s\+[^ ]*$' endfunction
return join(s:options(), "\n")
else
return ''
endif
endfunction function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort
let str = a:CmdLine[:a:CursorPos-1]
if str =~# '^Git\s\+tag\s\+-$'
return join(s:options(), "\n")
elseif str =~# '^Git\s\+tag\s\+[^ ]*$'
return join(s:options(), "\n")
else
return ''
endif
endfunction
endif

View File

@ -72,7 +72,14 @@ function M.run(argv)
end end
end end
function M.complete(ArgLead, CmdLine, CursorPos) end function M.complete(ArgLead, CmdLine, CursorPos)
local str = string.sub(CmdLine, 1, CursorPos)
if vim.regex([[^Git\s\+tag\s\+-\+$]]):match_str(str) then
return table.concat({'--list'}, '\n')
else
return ''
end
end
return M return M