mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 07:50:04 +08:00
feat(git): implement lua complete for git-tag
This commit is contained in:
parent
a0b86e67e8
commit
3ffa25addc
@ -6,88 +6,94 @@
|
||||
" :Git tag --list
|
||||
" <
|
||||
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:NT = SpaceVim#api#import('notify')
|
||||
let s:jobid = -1
|
||||
let s:stderr_data = []
|
||||
|
||||
function! git#tag#run(argvs) abort
|
||||
|
||||
if 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)
|
||||
|
||||
if has('nvim-0.9.0')
|
||||
function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort
|
||||
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"))')
|
||||
endfunction
|
||||
else
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:NT = SpaceVim#api#import('notify')
|
||||
let s:jobid = -1
|
||||
let s:stderr_data = []
|
||||
|
||||
let cmd = ['git', 'tag'] + a:argvs
|
||||
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'),
|
||||
\ }
|
||||
\ )
|
||||
function! git#tag#run(argvs) abort
|
||||
|
||||
if s:jobid == -1
|
||||
call s:NT.notify('`git` is not executable', 'WarningMsg')
|
||||
endif
|
||||
if s:jobid != -1
|
||||
call s:NT.notify('previous tag command is not finished')
|
||||
return
|
||||
endif
|
||||
|
||||
endfunction
|
||||
let s:NT.notify_max_width = float2nr(&columns * 0.3)
|
||||
|
||||
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)
|
||||
endfor
|
||||
endfunction
|
||||
let s:stderr_data = []
|
||||
|
||||
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
|
||||
endfunction
|
||||
let cmd = ['git', 'tag'] + a:argvs
|
||||
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'),
|
||||
\ }
|
||||
\ )
|
||||
|
||||
function! s:on_exit(id, data, event) abort
|
||||
call git#logger#debug('git-tag exit data:' . string(a:data))
|
||||
if a:id != s:jobid
|
||||
return
|
||||
endif
|
||||
if a:data ==# 0
|
||||
for line in s:stderr_data
|
||||
if s:jobid == -1
|
||||
call s:NT.notify('`git` is not executable', 'WarningMsg')
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
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)
|
||||
endfor
|
||||
else
|
||||
for line in s:stderr_data
|
||||
call s:NT.notify(line, 'WarningMsg')
|
||||
endfunction
|
||||
|
||||
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
|
||||
endif
|
||||
let s:jobid = -1
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:options() abort
|
||||
return [
|
||||
\ '--list',
|
||||
\ ]
|
||||
endfunction
|
||||
function! s:on_exit(id, data, event) abort
|
||||
call git#logger#debug('git-tag exit data:' . string(a:data))
|
||||
if a:id != s:jobid
|
||||
return
|
||||
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
|
||||
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
|
||||
function! s:options() abort
|
||||
return [
|
||||
\ '--list',
|
||||
\ ]
|
||||
endfunction
|
||||
|
||||
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
|
||||
|
@ -72,7 +72,14 @@ function M.run(argv)
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user