vim-polyglot/autoload/go/complete.vim

72 lines
1.6 KiB
VimL
Raw Normal View History

2013-09-12 10:26:29 -04:00
" Copyright 2011 The Go Authors. All rights reserved.
" Use of this source code is governed by a BSD-style
" license that can be found in the LICENSE file.
"
" This file provides a utility function that performs auto-completion of
" package names, for use by other commands.
let s:goos = $GOOS
let s:goarch = $GOARCH
if len(s:goos) == 0
if exists('g:golang_goos')
let s:goos = g:golang_goos
elseif has('win32') || has('win64')
let s:goos = 'windows'
elseif has('macunix')
let s:goos = 'darwin'
else
let s:goos = '*'
endif
endif
if len(s:goarch) == 0
if exists('g:golang_goarch')
let s:goarch = g:golang_goarch
else
let s:goarch = '*'
endif
endif
function! go#complete#Package(ArgLead, CmdLine, CursorPos)
let dirs = []
if executable('go')
2013-09-12 11:22:37 -04:00
let goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
if v:shell_error
echo '\'go env GOROOT\' failed'
endif
2013-09-12 10:26:29 -04:00
else
2013-09-12 11:22:37 -04:00
let goroot = $GOROOT
2013-09-12 10:26:29 -04:00
endif
if len(goroot) != 0 && isdirectory(goroot)
2013-09-12 11:22:37 -04:00
let dirs += [ goroot ]
2013-09-12 10:26:29 -04:00
endif
2013-09-12 11:22:37 -04:00
let workspaces = split($GOPATH, ':')
2013-09-12 10:26:29 -04:00
if workspaces != []
2013-09-12 11:22:37 -04:00
let dirs += workspaces
2013-09-12 10:26:29 -04:00
endif
if len(dirs) == 0
2013-09-12 11:22:37 -04:00
" should not happen
return []
2013-09-12 10:26:29 -04:00
endif
let ret = {}
for dir in dirs
2013-09-12 11:22:37 -04:00
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
2013-09-12 10:26:29 -04:00
endfor
endfor
return sort(keys(ret))
endfunction