2014-10-31 17:30:24 -04:00
|
|
|
if !exists("g:go_godef_bin")
|
|
|
|
let g:go_godef_bin = "godef"
|
|
|
|
endif
|
|
|
|
|
2016-02-20 08:13:10 -05:00
|
|
|
if go#vimproc#has_vimproc()
|
|
|
|
let s:vim_system = get(g:, 'gocomplete#system_function', 'vimproc#system2')
|
|
|
|
else
|
|
|
|
let s:vim_system = get(g:, 'gocomplete#system_function', 'system')
|
|
|
|
endif
|
|
|
|
|
|
|
|
fu! s:system(str, ...)
|
|
|
|
return call(s:vim_system, [a:str] + a:000)
|
|
|
|
endf
|
2014-10-31 17:30:24 -04:00
|
|
|
|
|
|
|
" modified and improved version of vim-godef
|
|
|
|
function! go#def#Jump(...)
|
|
|
|
if !len(a:000)
|
2016-03-20 14:01:44 -04:00
|
|
|
let arg = "-o=" . go#util#OffsetCursor()
|
2014-10-31 17:30:24 -04:00
|
|
|
else
|
|
|
|
let arg = a:1
|
|
|
|
endif
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
let bin_path = go#path#CheckBinPath(g:go_godef_bin)
|
2015-01-18 07:58:28 -05:00
|
|
|
if empty(bin_path)
|
|
|
|
return
|
2014-10-31 17:30:24 -04:00
|
|
|
endif
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
let old_gopath = $GOPATH
|
|
|
|
let $GOPATH = go#path#Detect()
|
|
|
|
|
2016-02-20 08:13:10 -05:00
|
|
|
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
|
|
|
let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
2014-10-31 17:30:24 -04:00
|
|
|
|
|
|
|
" get output of godef
|
2016-02-20 08:13:10 -05:00
|
|
|
let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
2014-10-31 17:30:24 -04:00
|
|
|
|
|
|
|
" jump to it
|
|
|
|
call s:godefJump(out, "")
|
2015-07-13 06:22:46 -04:00
|
|
|
let $GOPATH = old_gopath
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! go#def#JumpMode(mode)
|
2016-03-20 14:01:44 -04:00
|
|
|
let arg = "-o=" . go#util#OffsetCursor()
|
2014-10-31 17:30:24 -04:00
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
let bin_path = go#path#CheckBinPath(g:go_godef_bin)
|
2015-01-18 07:58:28 -05:00
|
|
|
if empty(bin_path)
|
|
|
|
return
|
2014-10-31 17:30:24 -04:00
|
|
|
endif
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
let old_gopath = $GOPATH
|
|
|
|
let $GOPATH = go#path#Detect()
|
|
|
|
|
2016-02-20 08:13:10 -05:00
|
|
|
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
|
|
|
let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
2014-10-31 17:30:24 -04:00
|
|
|
|
|
|
|
" get output of godef
|
2016-02-20 08:13:10 -05:00
|
|
|
let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
2014-10-31 17:30:24 -04:00
|
|
|
|
|
|
|
call s:godefJump(out, a:mode)
|
2015-07-13 06:22:46 -04:00
|
|
|
let $GOPATH = old_gopath
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:getOffset()
|
2016-03-20 14:01:44 -04:00
|
|
|
return "-o=" . go#util#OffsetCursor()
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
function! s:godefJump(out, mode)
|
|
|
|
let old_errorformat = &errorformat
|
|
|
|
let &errorformat = "%f:%l:%c"
|
|
|
|
|
|
|
|
if a:out =~ 'godef: '
|
2016-02-20 08:13:10 -05:00
|
|
|
let out = substitute(a:out, go#util#LineEnding() . '$', '', '')
|
2014-10-31 17:30:24 -04:00
|
|
|
echom out
|
|
|
|
else
|
|
|
|
let parts = split(a:out, ':')
|
|
|
|
" parts[0] contains filename
|
|
|
|
let fileName = parts[0]
|
|
|
|
|
|
|
|
" put the error format into location list so we can jump automatically to
|
|
|
|
" it
|
|
|
|
lgetexpr a:out
|
|
|
|
|
|
|
|
" needed for restoring back user setting this is because there are two
|
|
|
|
" modes of switchbuf which we need based on the split mode
|
|
|
|
let old_switchbuf = &switchbuf
|
|
|
|
|
|
|
|
if a:mode == "tab"
|
|
|
|
let &switchbuf = "usetab"
|
|
|
|
|
|
|
|
if bufloaded(fileName) == 0
|
2015-01-18 07:58:28 -05:00
|
|
|
tab split
|
2014-10-31 17:30:24 -04:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
if a:mode == "split"
|
|
|
|
split
|
|
|
|
elseif a:mode == "vsplit"
|
|
|
|
vsplit
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
" jump to file now
|
2015-01-18 07:58:28 -05:00
|
|
|
sil ll 1
|
2016-03-14 06:04:57 -04:00
|
|
|
normal! zz
|
2014-10-31 17:30:24 -04:00
|
|
|
|
|
|
|
let &switchbuf = old_switchbuf
|
|
|
|
end
|
|
|
|
let &errorformat = old_errorformat
|
|
|
|
endfunction
|