summaryrefslogtreecommitdiffstats
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/go/complete.vim70
1 files changed, 51 insertions, 19 deletions
diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim
index cc1013b7..8dd43de4 100644
--- a/autoload/go/complete.vim
+++ b/autoload/go/complete.vim
@@ -28,43 +28,75 @@ if len(s:goarch) == 0
endif
endif
+function! go#complete#PackageMembers(package, member)
+ silent! let content = system('godoc ' . a:package)
+ if v:shell_error || !len(content)
+ return []
+ endif
+ let lines = filter(split(content, "\n"),"v:val !~ '^\\s\\+$'")
+ try
+ let mx1 = '^\s\+\(\S+\)\s\+=\s\+.*'
+ let mx2 = '^\%(const\|var\|type\|func\) \([A-Z][^ (]\+\).*'
+ let candidates =
+ \ map(filter(copy(lines), 'v:val =~ mx1'), 'substitute(v:val, mx1, "\\1", "")')
+ \ + map(filter(copy(lines), 'v:val =~ mx2'), 'substitute(v:val, mx2, "\\1", "")')
+ return filter(candidates, '!stridx(v:val, a:member)')
+ catch
+ return []
+ endtry
+endfunction
+
function! go#complete#Package(ArgLead, CmdLine, CursorPos)
let dirs = []
+ let words = split(a:CmdLine, '\s\+', 1)
+ if len(words) > 2
+ " Complete package members
+ return go#complete#PackageMembers(words[1], words[2])
+ endif
+
if executable('go')
- let goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
- if v:shell_error
- echo '\'go env GOROOT\' failed'
- endif
+ let goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
+ if v:shell_error
+ echomsg '\'go env GOROOT\' failed'
+ endif
else
- let goroot = $GOROOT
+ let goroot = $GOROOT
endif
if len(goroot) != 0 && isdirectory(goroot)
- let dirs += [ goroot ]
+ let dirs += [goroot]
endif
- let workspaces = split($GOPATH, ':')
+ let pathsep = ':'
+ if s:goos == 'windows'
+ let pathsep = ';'
+ endif
+ let workspaces = split($GOPATH, pathsep)
if workspaces != []
- let dirs += workspaces
+ let dirs += workspaces
endif
if len(dirs) == 0
- " should not happen
- return []
+ " should not happen
+ return []
endif
let ret = {}
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
+ " this may expand to multiple lines
+ let root = split(expand(dir . '/pkg/' . s:goos . '_' . s:goarch), "\n")
+ call add(root, expand(dir . '/src'))
+ for r in root
+ for i in split(globpath(r, a:ArgLead.'*'), "\n")
+ if isdirectory(i)
+ let i .= '/'
+ elseif i !~ '\.a$'
+ continue
+ endif
+ let i = substitute(substitute(i[len(r)+1:], '[\\]', '/', 'g'), '\.a$', '', 'g')
+ let ret[i] = i
+ endfor
endfor
endfor
return sort(keys(ret))