Skip to content

Commit

Permalink
Add completion for revision range
Browse files Browse the repository at this point in the history
  • Loading branch information
zldrobit committed May 8, 2022
1 parent b7287bd commit 07de0b8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions autoload/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,17 @@ function! s:CompleteHeads(dir) abort
\ sort(s:LinesError([a:dir, 'rev-parse', '--symbolic', '--branches', '--tags', '--remotes'])[0])
endfunction

function! s:SplitRevRange(base, pat)
let index = matchend(a:base, a:pat)
if index == -1
return ['', a:base]
endif
let pre = a:base[:index - 1]
let base = a:base[index:]
return [pre, base]
endif
endfunction

function! fugitive#CompleteObject(base, ...) abort
let dir = a:0 == 1 ? a:1 : a:0 >= 3 ? a:3 : s:Dir()
let tree = s:Tree(dir)
Expand All @@ -2424,9 +2435,10 @@ function! fugitive#CompleteObject(base, ...) abort
let subdir = strpart(cwd, len(tree) + 1) . '/'
endif
let base = s:Expand(a:base)
let [pre, base] = s:SplitRevRange(base, '^[^:]*\/\@<!\.\.\.\=[\/\.]\@!')

if a:base =~# '^!\d*$' && base !~# '^!'
return [base]
return [pre . base]
elseif base =~# '^\.\=/\|^:(' || base !~# ':'
let results = []
if base =~# '^refs/'
Expand All @@ -2442,6 +2454,7 @@ function! fugitive#CompleteObject(base, ...) abort
let results += s:FilterEscape(heads, fnameescape(base))
endif
let results += a:0 == 1 || a:0 >= 3 ? fugitive#CompletePath(base, 0, '', dir, a:0 >= 4 ? a:4 : tree) : fugitive#CompletePath(base)
let results = map(results, 'pre . v:val')
return results

elseif base =~# '^:'
Expand All @@ -2461,7 +2474,7 @@ function! fugitive#CompleteObject(base, ...) abort
call map(entries,'s:sub(v:val,"^04.*\\zs$","/")')
call map(entries,'parent.s:sub(v:val,".*\t","")')
endif
return s:FilterEscape(entries, fnameescape(base))
return map(s:FilterEscape(entries, fnameescape(base)), 'pre . v:val')
endfunction

function! s:CompleteSub(subcommand, A, L, P, ...) abort
Expand Down

0 comments on commit 07de0b8

Please sign in to comment.