Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #287 from obcat/cmdline-completion
Browse files Browse the repository at this point in the history
Some improvements to cmdline completion
  • Loading branch information
lambdalisue authored Apr 27, 2021
2 parents 97116f3 + 932e8e5 commit e8ad68b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
2 changes: 0 additions & 2 deletions autoload/gina/command.vim
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ function! gina#command#complete(arglead, cmdline, cursorpos) abort
\)
elseif a:cmdline =~# printf('^.\{-}Gina\s\+%s$', a:arglead)
return gina#complete#common#command(a:arglead, a:cmdline, a:cursorpos)
else
return []
endif
let cmdline = matchstr(a:cmdline, '^.\{-}Gina\s\+\zs.*')
let scheme = matchstr(cmdline, '^\S\+')
Expand Down
50 changes: 49 additions & 1 deletion autoload/gina/command/_raw.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ function! gina#command#_raw#call(range, args, mods) abort
endfunction

function! gina#command#_raw#complete(arglead, cmdline, cursorpos) abort
return gina#complete#filename#any(a:arglead, a:cmdline, a:cursorpos)
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
if empty(args.get(1))
return gina#complete#common#raw_command(a:arglead, a:cmdline, a:cursorpos)
endif
if args.get(1) =~# '^\%(fetch\|pull\|push\|switch\)$'
return s:{args.get(1)}_complete(a:arglead, a:cmdline, a:cursorpos)
endif
return []
endfunction


Expand All @@ -22,6 +29,47 @@ function! s:build_args(git, args) abort
return args.lock()
endfunction

function! s:fetch_complete(arglead, cmdline, cursorpos) abort
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
if empty(args.get(2))
return gina#complete#common#remote(a:arglead, a:cmdline, a:cursorpos)
endif
if empty(args.get(3))
" TODO: Return refspecs in remote repository "args.get(2)".
endif
return []
endfunction

function! s:pull_complete(arglead, cmdline, cursorpos) abort
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
if empty(args.get(2))
return gina#complete#common#remote(a:arglead, a:cmdline, a:cursorpos)
endif
if empty(args.get(3))
" TODO: Return refspecs in remote repository "args.get(2)".
endif
return []
endfunction

function! s:push_complete(arglead, cmdline, cursorpos) abort
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
if empty(args.get(2))
return gina#complete#common#remote(a:arglead, a:cmdline, a:cursorpos)
endif
if empty(args.get(3))
return gina#complete#commit#local_branch(a:arglead, a:cmdline, a:cursorpos)
endif
return []
endfunction

function! s:switch_complete(arglead, cmdline, cursorpos) abort
let args = gina#core#args#new(matchstr(a:cmdline, '^.*\ze .*'))
if empty(args.get(2))
return gina#complete#commit#local_branch(a:arglead, a:cmdline, a:cursorpos)
endif
return []
endfunction


" Pipe -----------------------------------------------------------------------
function! s:_pipe_on_exit(exitval) abort dict
Expand Down
36 changes: 36 additions & 0 deletions autoload/gina/complete/common.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ function! gina#complete#common#command(arglead, cmdline, cursorpos) abort
return gina#util#filter(a:arglead, command_names, '^_')
endfunction

function! gina#complete#common#raw_command(arglead, cmdline, cursorpos) abort
return gina#util#filter(a:arglead, [
\ 'add',
\ 'bisect',
\ 'branch',
\ 'checkout',
\ 'clone',
\ 'commit',
\ 'diff',
\ 'fetch',
\ 'grep',
\ 'init',
\ 'log',
\ 'merge',
\ 'mv',
\ 'pull',
\ 'push',
\ 'rebase',
\ 'reset',
\ 'restore',
\ 'rm',
\ 'show',
\ 'status',
\ 'switch',
\ 'tag',
\])
endfunction

function! gina#complete#common#remote(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let result = gina#process#call(git, ['remote'])
if result.status
return []
endif
return gina#util#filter(a:arglead, result.stdout)
endfunction

" Private --------------------------------------------------------------------
function! s:get_cache() abort
Expand Down

0 comments on commit e8ad68b

Please sign in to comment.