diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /misc/vim/autoload/go/complete.vim | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'misc/vim/autoload/go/complete.vim')
-rw-r--r-- | misc/vim/autoload/go/complete.vim | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/misc/vim/autoload/go/complete.vim b/misc/vim/autoload/go/complete.vim index d4ae3b97f..cc1013b7d 100644 --- a/misc/vim/autoload/go/complete.vim +++ b/misc/vim/autoload/go/complete.vim @@ -29,21 +29,43 @@ if len(s:goarch) == 0 endif function! go#complete#Package(ArgLead, CmdLine, CursorPos) - let goroot = $GOROOT - if len(goroot) == 0 - " should not occur. - return [] + let dirs = [] + + if executable('go') + let goroot = substitute(system('go env GOROOT'), '\n', '', 'g') + if v:shell_error + echo '\'go env GOROOT\' failed' + endif + else + let goroot = $GOROOT endif + + if len(goroot) != 0 && isdirectory(goroot) + let dirs += [ goroot ] + endif + + let workspaces = split($GOPATH, ':') + if workspaces != [] + let dirs += workspaces + endif + + if len(dirs) == 0 + " should not happen + return [] + endif + let ret = {} - let root = expand(goroot.'/pkg/'.s:goos.'_'.s:goarch) - for i in split(globpath(root, a:ArgLead.'*'), "\n") - if isdirectory(i) - let i .= '/' - elseif i !~ '\.a$' - continue - endif - let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g') - let ret[i] = i + for dir in dirs + let root = expand(dir . '/pkg/' . s:goos . '_' . s:goarch) + for i in split(globpath(root, a:ArgLead.'*'), "\n") + if isdirectory(i) + let i .= '/' + elseif i !~ '\.a$' + continue + endif + let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g') + let ret[i] = i + endfor endfor return sort(keys(ret)) endfunction |