Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add completion for revision range #1975

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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