1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:20:22 -07:00

misc/vim: Autocompletion for :Godoc command

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/14259043
This commit is contained in:
Yasuhiro Matsumoto 2013-10-03 13:32:07 +10:00 committed by David Symonds
parent 94a6511b7f
commit 45b830ed31

View File

@ -28,13 +28,31 @@ 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
" TODO Complete package members
return []
" Complete package members
return go#complete#PackageMembers(words[1], words[2])
endif
if executable('go')