1
0
mirror of https://github.com/golang/go synced 2024-11-25 14:17:57 -07:00

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 #3876
    Fixes #3882

R=golang-dev, franciscossouza, dsymonds, minux.ma
CC=golang-dev
https://golang.org/cl/6443151
This commit is contained in:
Tobias Columbus 2012-08-28 03:59:16 +08:00 committed by Shenghou Ma
parent e2a83b47e7
commit 5e8de365dc
2 changed files with 36 additions and 14 deletions

View File

@ -29,13 +29,34 @@ if len(s:goarch) == 0
endif endif
function! go#complete#Package(ArgLead, CmdLine, CursorPos) function! go#complete#Package(ArgLead, CmdLine, CursorPos)
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 let goroot = $GOROOT
if len(goroot) == 0 endif
" should not occur.
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 [] return []
endif endif
let ret = {} let ret = {}
let root = expand(goroot.'/pkg/'.s:goos.'_'.s:goarch) for dir in dirs
let root = expand(dir . '/pkg/' . s:goos . '_' . s:goarch)
for i in split(globpath(root, a:ArgLead.'*'), "\n") for i in split(globpath(root, a:ArgLead.'*'), "\n")
if isdirectory(i) if isdirectory(i)
let i .= '/' let i .= '/'
@ -45,5 +66,6 @@ function! go#complete#Package(ArgLead, CmdLine, CursorPos)
let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g') let i = substitute(substitute(i[len(root)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g')
let ret[i] = i let ret[i] = i
endfor endfor
endfor
return sort(keys(ret)) return sort(keys(ret))
endfunction endfunction

View File

@ -72,7 +72,7 @@ function! s:Godoc(...)
if !len(word) if !len(word)
let word = expand('<cword>') let word = expand('<cword>')
endif endif
let word = substitute(word, '[^a-zA-Z0-9\/]', '', 'g') let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g')
if !len(word) if !len(word)
return return
endif endif