diff --git a/bundle/git.vim/autoload/git/reset.vim b/bundle/git.vim/autoload/git/reset.vim index 7359a28ba..385d0c354 100644 --- a/bundle/git.vim/autoload/git/reset.vim +++ b/bundle/git.vim/autoload/git/reset.vim @@ -1,37 +1,50 @@ -let s:JOB = SpaceVim#api#import('job') +"============================================================================= +" 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') -function! git#reset#run(args) + function! git#reset#run(args) if len(a:args) == 1 && a:args[0] ==# '%' - let cmd = ['git', 'reset', 'HEAD', expand('%')] + let cmd = ['git', 'reset', 'HEAD', expand('%')] else - let cmd = ['git', 'reset'] + a:args + let cmd = ['git', 'reset'] + a:args endif call git#logger#debug('git-reset cmd:' . string(cmd)) call s:JOB.start(cmd, - \ { - \ 'on_exit' : function('s:on_exit'), - \ } - \ ) + \ { + \ 'on_exit' : function('s:on_exit'), + \ } + \ ) -endfunction + endfunction -function! s:on_exit(id, data, event) abort + function! s:on_exit(id, data, event) abort call git#logger#debug('git-reset exit data:' . string(a:data)) if a:data ==# 0 - if exists(':GitGutter') - GitGutter - endif - echo 'done!' + if exists(':GitGutter') + GitGutter + endif + echo 'done!' else - echo 'failed!' + echo 'failed!' endif -endfunction + endfunction -function! git#reset#complete(ArgLead, CmdLine, CursorPos) + function! git#reset#complete(ArgLead, CmdLine, CursorPos) return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n") -endfunction - + endfunction +endif diff --git a/bundle/git.vim/autoload/git/rm.vim b/bundle/git.vim/autoload/git/rm.vim index 96c0accf9..b5f37874f 100644 --- a/bundle/git.vim/autoload/git/rm.vim +++ b/bundle/git.vim/autoload/git/rm.vim @@ -7,38 +7,44 @@ " :Git rm % " < -let s:JOB = SpaceVim#api#import('job') +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') -function! git#rm#run(files) abort + function! git#rm#run(files) abort if len(a:files) == 1 && a:files[0] ==# '%' - let cmd = ['git', 'rm', expand('%')] + let cmd = ['git', 'rm', expand('%')] else - let cmd = ['git', 'rm'] + a:files + let cmd = ['git', 'rm'] + a:files endif call git#logger#debug('git-rm cmd:' . string(cmd)) call s:JOB.start(cmd, - \ { - \ 'on_exit' : function('s:on_exit'), - \ } - \ ) + \ { + \ 'on_exit' : function('s:on_exit'), + \ } + \ ) -endfunction + endfunction -function! s:on_exit(id, data, event) abort + function! s:on_exit(id, data, event) abort call git#logger#debug('git-rm exit data:' . string(a:data)) if a:data ==# 0 - if exists(':GitGutter') - GitGutter - endif - echo 'done!' + if exists(':GitGutter') + GitGutter + endif + echo 'done!' else - echo 'failed!' + echo 'failed!' endif -endfunction + endfunction -function! git#rm#complete(ArgLead, CmdLine, CursorPos) abort + function! git#rm#complete(ArgLead, CmdLine, CursorPos) abort return "%\n" . join(getcompletion(a:ArgLead, 'file'), "\n") -endfunction + endfunction +endif diff --git a/bundle/git.vim/autoload/git/stash.vim b/bundle/git.vim/autoload/git/stash.vim index a4a1c4822..5a741fc2e 100644 --- a/bundle/git.vim/autoload/git/stash.vim +++ b/bundle/git.vim/autoload/git/stash.vim @@ -6,104 +6,109 @@ " :Git stash list " < -let s:JOB = SpaceVim#api#import('job') -let s:NOTI = SpaceVim#api#import('notify') -let s:BUFFER = SpaceVim#api#import('vim#buffer') +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:NOTI = SpaceVim#api#import('notify') + let s:BUFFER = SpaceVim#api#import('vim#buffer') -let s:stash_show_bufnr = -1 -" @todo rewrite Git stash in lua -function! git#stash#run(args) abort + let s:stash_show_bufnr = -1 + " @todo rewrite Git stash in lua + function! git#stash#run(args) abort let cmd = ['git', 'stash'] + a:args let subcmd = get(a:args, 0, '') if !empty(subcmd) && index(['drop', 'show'], subcmd) > -1 - let subcmd = subcmd . '_' + let subcmd = subcmd . '_' else - let subcmd = '' + let subcmd = '' endif call git#logger#debug('git-stash cmd:' . string(cmd)) let s:lines = [] call s:JOB.start(cmd, - \ { - \ 'on_stderr' : function('s:on_' . subcmd . 'stderr'), - \ 'on_stdout' : function('s:on_' . subcmd . 'stdout'), - \ 'on_exit' : function('s:on_' . subcmd . 'exit'), - \ } - \ ) -endfunction + \ { + \ 'on_stderr' : function('s:on_' . subcmd . 'stderr'), + \ 'on_stdout' : function('s:on_' . subcmd . 'stdout'), + \ 'on_exit' : function('s:on_' . subcmd . 'exit'), + \ } + \ ) + endfunction -function! s:on_stdout(id, data, event) abort + function! s:on_stdout(id, data, event) abort for line in filter(a:data, '!empty(v:val)') - call git#logger#debug('git-stash stdout:' . line) - call s:NOTI.notify(line, 'Normal') + call git#logger#debug('git-stash stdout:' . line) + call s:NOTI.notify(line, 'Normal') endfor -endfunction + endfunction -function! s:on_stderr(id, data, event) abort + function! s:on_stderr(id, data, event) abort for data in a:data - call git#logger#debug('git-stash stderr:' . data) + call git#logger#debug('git-stash stderr:' . data) endfor -endfunction + endfunction -function! s:on_exit(id, data, event) abort + function! s:on_exit(id, data, event) abort call git#logger#debug('git-stash exit data:' . string(a:data)) if a:data ==# 0 - " echo 'done!' + " echo 'done!' else - " echo 'failed!' + " echo 'failed!' endif -endfunction + endfunction -function! s:on_drop_stdout(id, data, event) abort + function! s:on_drop_stdout(id, data, event) abort for line in filter(a:data, '!empty(v:val)') - call git#logger#debug('git-stash stdout:' . line) - call s:NOTI.notify(line, 'Normal') + call git#logger#debug('git-stash stdout:' . line) + call s:NOTI.notify(line, 'Normal') endfor -endfunction + endfunction -function! s:on_drop_stderr(id, data, event) abort + function! s:on_drop_stderr(id, data, event) abort for line in filter(a:data, '!empty(v:val)') - call git#logger#debug('git-stash stdout:' . line) - call s:NOTI.notify(line, 'WarningMsg') + call git#logger#debug('git-stash stdout:' . line) + call s:NOTI.notify(line, 'WarningMsg') endfor -endfunction + endfunction -function! s:on_drop_exit(id, data, event) abort + function! s:on_drop_exit(id, data, event) abort call git#logger#debug('git-stash exit data:' . string(a:data)) if a:data ==# 0 - " echo 'done!' + " echo 'done!' else - " echo 'failed!' + " echo 'failed!' endif -endfunction + endfunction -function! s:on_show_stdout(id, data, event) abort + function! s:on_show_stdout(id, data, event) abort for data in a:data - call git#logger#debug('git-stash stdout:' . data) + call git#logger#debug('git-stash stdout:' . data) endfor let s:lines += a:data -endfunction + endfunction -function! s:on_show_stderr(id, data, event) abort + function! s:on_show_stderr(id, data, event) abort for line in filter(a:data, '!empty(v:val)') - call git#logger#debug('git-stash stdout:' . line) - call s:NOTI.notify(line, 'WarningMsg') + call git#logger#debug('git-stash stdout:' . line) + call s:NOTI.notify(line, 'WarningMsg') endfor -endfunction + endfunction -function! s:on_show_exit(id, data, event) abort + function! s:on_show_exit(id, data, event) abort call git#logger#debug('git-stash exit data:' . string(a:data)) if a:data ==# 0 - if !bufexists(s:stash_show_bufnr) - let s:stash_show_bufnr = s:openStashShowBuffer() - endif - call s:BUFFER.buf_set_lines(s:stash_show_bufnr, 0 , -1, 0, s:lines) + if !bufexists(s:stash_show_bufnr) + let s:stash_show_bufnr = s:openStashShowBuffer() + endif + call s:BUFFER.buf_set_lines(s:stash_show_bufnr, 0 , -1, 0, s:lines) endif -endfunction + endfunction -function! s:openStashShowBuffer() abort + function! s:openStashShowBuffer() abort edit git://blame normal! "_dd setl nobuflisted @@ -114,30 +119,31 @@ function! s:openStashShowBuffer() abort setl syntax=diff nnoremap q :bd! return bufnr('%') -endfunction + endfunction -function! s:sub_commands() abort + function! s:sub_commands() abort return join([ - \ 'list', - \ 'show', - \ 'drop', - \ 'pop', 'apply', - \ 'branch', - \ 'clear', - \ 'save', - \ 'push', - \ ], - \ "\n") -endfunction + \ 'list', + \ 'show', + \ 'drop', + \ 'pop', 'apply', + \ 'branch', + \ 'clear', + \ 'save', + \ 'push', + \ ], + \ "\n") + endfunction -function! git#stash#complete(ArgLead, CmdLine, CursorPos) abort + function! git#stash#complete(ArgLead, CmdLine, CursorPos) abort let str = a:CmdLine[:a:CursorPos-1] if str =~# '^Git\s\+stash\s\+[a-z]\=$' - return s:sub_commands() + return s:sub_commands() else - return '' + return '' endif -endfunction + endfunction +endif diff --git a/bundle/git.vim/lua/git/command/reset.lua b/bundle/git.vim/lua/git/command/reset.lua index 74b5ccaee..42654ba04 100644 --- a/bundle/git.vim/lua/git/command/reset.lua +++ b/bundle/git.vim/lua/git/command/reset.lua @@ -5,7 +5,7 @@ -- URL: https://spacevim.org -- License: GPLv3 --============================================================================= -local m = {} +local M = {} local job = require('spacevim.api.job') local nt = require('spacevim.api.notify') @@ -23,7 +23,7 @@ local function on_exit(id, code, single) end end -function m.run(argv) +function M.run(argv) local cmd = { 'git', 'reset' } if #argv == 1 and argv[1] == '%' then cmd = { 'git', 'reset', 'HEAD', vim.fn.expand('%') } @@ -38,4 +38,9 @@ function m.run(argv) }) end -return m +function M.complete(ArgLead, CmdLine, CursorPos) + local rst = vim.fn.getcompletion(ArgLead, 'file') + return table.concat(rst, '\n') +end + +return M diff --git a/bundle/git.vim/lua/git/command/rm.lua b/bundle/git.vim/lua/git/command/rm.lua index a02fa9915..33b5a1674 100644 --- a/bundle/git.vim/lua/git/command/rm.lua +++ b/bundle/git.vim/lua/git/command/rm.lua @@ -47,4 +47,9 @@ function m.run(argv) }) end +function M.complete(ArgLead, CmdLine, CursorPos) + local rst = vim.fn.getcompletion(ArgLead, 'file') + return table.concat(rst, '\n') +end + return m diff --git a/bundle/git.vim/lua/git/command/stash.lua b/bundle/git.vim/lua/git/command/stash.lua index 9af691256..f83911c87 100644 --- a/bundle/git.vim/lua/git/command/stash.lua +++ b/bundle/git.vim/lua/git/command/stash.lua @@ -97,4 +97,27 @@ function M.run(argv) 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