mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:50:04 +08:00
feat(git): implement lua complete for git-tag
This commit is contained in:
parent
a0b86e67e8
commit
3ffa25addc
@ -6,12 +6,17 @@
|
|||||||
" :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
|
||||||
|
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
|
function! git#tag#run(argvs) abort
|
||||||
|
|
||||||
if s:jobid != -1
|
if s:jobid != -1
|
||||||
call s:NT.notify('previous tag command is not finished')
|
call s:NT.notify('previous tag command is not finished')
|
||||||
@ -36,27 +41,27 @@ function! git#tag#run(argvs) abort
|
|||||||
call s:NT.notify('`git` is not executable', 'WarningMsg')
|
call s:NT.notify('`git` is not executable', 'WarningMsg')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_stdout(id, data, event) abort
|
function! s:on_stdout(id, data, event) abort
|
||||||
if a:id != s:jobid
|
if a:id != s:jobid
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
for line in a:data
|
for line in a:data
|
||||||
call s:NT.notify(line)
|
call s:NT.notify(line)
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_stderr(id, data, event) abort
|
function! s:on_stderr(id, data, event) abort
|
||||||
if a:id != s:jobid
|
if a:id != s:jobid
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
for line in a:data
|
for line in a:data
|
||||||
call add(s:stderr_data, line)
|
call add(s:stderr_data, line)
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:on_exit(id, data, event) abort
|
function! s:on_exit(id, data, event) abort
|
||||||
call git#logger#debug('git-tag exit data:' . string(a:data))
|
call git#logger#debug('git-tag exit data:' . string(a:data))
|
||||||
if a:id != s:jobid
|
if a:id != s:jobid
|
||||||
return
|
return
|
||||||
@ -71,15 +76,15 @@ function! s:on_exit(id, data, event) abort
|
|||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
let s:jobid = -1
|
let s:jobid = -1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:options() abort
|
function! s:options() abort
|
||||||
return [
|
return [
|
||||||
\ '--list',
|
\ '--list',
|
||||||
\ ]
|
\ ]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort
|
function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort
|
||||||
let str = a:CmdLine[:a:CursorPos-1]
|
let str = a:CmdLine[:a:CursorPos-1]
|
||||||
if str =~# '^Git\s\+tag\s\+-$'
|
if str =~# '^Git\s\+tag\s\+-$'
|
||||||
return join(s:options(), "\n")
|
return join(s:options(), "\n")
|
||||||
@ -89,5 +94,6 @@ function! git#tag#complete(ArgLead, CmdLine, CursorPos) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user