mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Updated plugins
This commit is contained in:
@ -4,18 +4,14 @@
|
||||
|
||||
let s:buf_nr = -1
|
||||
|
||||
if !exists("g:go_doc_command")
|
||||
let g:go_doc_command = ["godoc"]
|
||||
endif
|
||||
|
||||
function! go#doc#OpenBrowser(...) abort
|
||||
" check if we have gogetdoc as it gives us more and accurate information.
|
||||
" Only supported if we have json_decode as it's not worth to parse the plain
|
||||
" non-json output of gogetdoc
|
||||
let bin_path = go#path#CheckBinPath('gogetdoc')
|
||||
if !empty(bin_path) && exists('*json_decode')
|
||||
let json_out = s:gogetdoc(1)
|
||||
if go#util#ShellError() != 0
|
||||
let [l:json_out, l:err] = s:gogetdoc(1)
|
||||
if l:err
|
||||
call go#util#EchoError(json_out)
|
||||
return
|
||||
endif
|
||||
@ -29,14 +25,12 @@ function! go#doc#OpenBrowser(...) abort
|
||||
let name = out["name"]
|
||||
let decl = out["decl"]
|
||||
|
||||
let godoc_url = s:custom_godoc_url()
|
||||
let godoc_url = go#config#DocUrl()
|
||||
let godoc_url .= "/" . import
|
||||
if decl !~ "^package"
|
||||
let godoc_url .= "#" . name
|
||||
endif
|
||||
|
||||
echo godoc_url
|
||||
|
||||
call go#tool#OpenBrowser(godoc_url)
|
||||
return
|
||||
endif
|
||||
@ -50,28 +44,27 @@ function! go#doc#OpenBrowser(...) abort
|
||||
let exported_name = pkgs[1]
|
||||
|
||||
" example url: https://godoc.org/github.com/fatih/set#Set
|
||||
let godoc_url = s:custom_godoc_url() . "/" . pkg . "#" . exported_name
|
||||
let godoc_url = go#config#DocUrl() . "/" . pkg . "#" . exported_name
|
||||
call go#tool#OpenBrowser(godoc_url)
|
||||
endfunction
|
||||
|
||||
function! go#doc#Open(newmode, mode, ...) abort
|
||||
" With argument: run "godoc [arg]".
|
||||
if len(a:000)
|
||||
if empty(go#path#CheckBinPath(g:go_doc_command[0]))
|
||||
if empty(go#path#CheckBinPath(go#config#DocCommand()[0]))
|
||||
return
|
||||
endif
|
||||
|
||||
let command = printf("%s %s", go#util#Shelljoin(g:go_doc_command), join(a:000, ' '))
|
||||
let out = go#util#System(command)
|
||||
let [l:out, l:err] = go#util#Exec(go#config#DocCommand() + a:000)
|
||||
" Without argument: run gogetdoc on cursor position.
|
||||
else
|
||||
let out = s:gogetdoc(0)
|
||||
let [l:out, l:err] = s:gogetdoc(0)
|
||||
if out == -1
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
if go#util#ShellError() != 0
|
||||
if l:err
|
||||
call go#util#EchoError(out)
|
||||
return
|
||||
endif
|
||||
@ -97,7 +90,7 @@ function! s:GodocView(newposition, position, content) abort
|
||||
if !is_visible
|
||||
if a:position == "split"
|
||||
" cap window height to 20, but resize it for smaller contents
|
||||
let max_height = get(g:, "go_doc_max_height", 20)
|
||||
let max_height = go#config#DocMaxHeight()
|
||||
let content_height = len(split(a:content, "\n"))
|
||||
if content_height > max_height
|
||||
exe 'resize ' . max_height
|
||||
@ -135,33 +128,20 @@ function! s:GodocView(newposition, position, content) abort
|
||||
endfunction
|
||||
|
||||
function! s:gogetdoc(json) abort
|
||||
" check if we have 'gogetdoc' and use it automatically
|
||||
let bin_path = go#path#CheckBinPath('gogetdoc')
|
||||
if empty(bin_path)
|
||||
return -1
|
||||
endif
|
||||
|
||||
let cmd = [go#util#Shellescape(bin_path)]
|
||||
|
||||
let offset = go#util#OffsetCursor()
|
||||
let fname = expand("%:p:gs!\\!/!")
|
||||
let pos = shellescape(fname.':#'.offset)
|
||||
|
||||
let cmd += ["-pos", pos]
|
||||
let l:cmd = [
|
||||
\ 'gogetdoc',
|
||||
\ '-tags', go#config#BuildTags(),
|
||||
\ '-pos', expand("%:p:gs!\\!/!") . ':#' . go#util#OffsetCursor()]
|
||||
if a:json
|
||||
let cmd += ["-json"]
|
||||
let l:cmd += ['-json']
|
||||
endif
|
||||
|
||||
let command = join(cmd, " ")
|
||||
|
||||
if &modified
|
||||
let command .= " -modified"
|
||||
let out = go#util#System(command, go#util#archive())
|
||||
else
|
||||
let out = go#util#System(command)
|
||||
let l:cmd += ['-modified']
|
||||
return go#util#Exec(l:cmd, go#util#archive())
|
||||
endif
|
||||
|
||||
return out
|
||||
return go#util#Exec(l:cmd)
|
||||
endfunction
|
||||
|
||||
" returns the package and exported name. exported name might be empty.
|
||||
@ -206,18 +186,4 @@ function! s:godocWord(args) abort
|
||||
return [pkg, exported_name]
|
||||
endfunction
|
||||
|
||||
function! s:custom_godoc_url() abort
|
||||
let godoc_url = get(g:, 'go_doc_url', 'https://godoc.org')
|
||||
if godoc_url isnot 'https://godoc.org'
|
||||
" strip last '/' character if available
|
||||
let last_char = strlen(godoc_url) - 1
|
||||
if godoc_url[last_char] == '/'
|
||||
let godoc_url = strpart(godoc_url, 0, last_char)
|
||||
endif
|
||||
" custom godoc installations expect /pkg before package names
|
||||
let godoc_url .= "/pkg"
|
||||
endif
|
||||
return godoc_url
|
||||
endfunction
|
||||
|
||||
" vim: sw=2 ts=2 et
|
||||
|
Reference in New Issue
Block a user