diff options
author | Tobias Columbus <tobias.columbus@gmail.com> | 2012-08-28 03:59:16 +0800 |
---|---|---|
committer | Tobias Columbus <tobias.columbus@gmail.com> | 2012-08-28 03:59:16 +0800 |
commit | aefe2e492027e1dcb300b8058734fdaa86af88fc (patch) | |
tree | 44bb95e9a6eb1a448128cc3913a450e9abe08b3e /misc/vim | |
parent | 6bc7e0bc6520b946b776692df65ae9f87ec39e56 (diff) | |
download | go-aefe2e492027e1dcb300b8058734fdaa86af88fc.tar.gz |
misc/vim: fix for autocompletion
Vim autocompletion respects the $GOPATH variable and does not
ignore dashes ('-'), dots ('.') and underscores ('_') like found
in many remote packages.
Environment variable $GOROOT is determined by calling
'go env GOROOT' instead of relying on the user's environment
variables.
Fixes issue 3876
Fixes issue 3882
R=golang-dev, franciscossouza, dsymonds, minux.ma
CC=golang-dev
http://codereview.appspot.com/6443151
Committer: Shenghou Ma <minux.ma@gmail.com>
Diffstat (limited to 'misc/vim')
-rw-r--r-- | misc/vim/autoload/go/complete.vim | 48 | ||||
-rw-r--r-- | misc/vim/plugin/godoc.vim | 2 |
2 files changed, 36 insertions, 14 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 diff --git a/misc/vim/plugin/godoc.vim b/misc/vim/plugin/godoc.vim index fdb496631..a9abb7ae6 100644 --- a/misc/vim/plugin/godoc.vim +++ b/misc/vim/plugin/godoc.vim @@ -72,7 +72,7 @@ function! s:Godoc(...) if !len(word) let word = expand('<cword>') endif - let word = substitute(word, '[^a-zA-Z0-9\/]', '', 'g') + let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') if !len(word) return endif |