Skip to content

Commit 1d6e948

Browse files
author
Blackrush
committed
start of package completion in GoInstall and GoTest see #1
1 parent 026060b commit 1d6e948

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

ftplugin/go/install.vim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@ if exists("b:did_ftplugin_go_install")
22
finish
33
endif
44

5-
command! -buffer -nargs=1 GoInstall call s:GoInstall(@%, <f-args>)
5+
function! GocodeCompletePkg(arg, cmd, index)
6+
let s:base=DirName(@%)
7+
let s:dirs=filter(split(globpath(s:base, a:arg.'*'), '\n'), 'isdirectory(v:val)')
8+
let s:ndirs=len(s:dirs)
9+
10+
if s:ndirs <= 0
11+
return ''
12+
elseif s:ndirs == 1
13+
let s:matched=s:dirs[0]
14+
else
15+
let s:matched=s:dirs[0] " TODO select the next match
16+
endif
17+
18+
return substitute(s:matched, s:base.'/', '', '').'/' " add a trailing / to quickly match a child
19+
endfunction
20+
21+
command! -buffer -nargs=1 -complete=custom,GocodeCompletePkg GoInstall call s:GoInstall(@%, <f-args>)
622
function! s:GoInstall(file, relpkg)
723
let pkg=GoRelPkg(a:file, a:relpkg)
824
if pkg != -1
@@ -17,7 +33,7 @@ function! s:GoInstall(file, relpkg)
1733
endif
1834
endfunction
1935

20-
command! -buffer -nargs=1 GoTest call s:GoTest(@%, <f-args>)
36+
command! -buffer -nargs=1 -complete=custom,GocodeCompletePkg GoTest call s:GoTest(@%, <f-args>)
2137
function! s:GoTest(file, relpkg)
2238
let pkg=GoRelPkg(a:file, a:relpkg)
2339
if pkg != -1

0 commit comments

Comments
 (0)