2018-12-17 06:28:27 -05:00
|
|
|
" don't spam the user when Vim is started in Vi compatibility mode
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2017-09-02 06:43:18 -04:00
|
|
|
" From "go list -h".
|
|
|
|
function! go#tool#ValidFiles(...)
|
|
|
|
let l:list = ["GoFiles", "CgoFiles", "IgnoredGoFiles", "CFiles", "CXXFiles",
|
|
|
|
\ "MFiles", "HFiles", "FFiles", "SFiles", "SwigFiles", "SwigCXXFiles",
|
|
|
|
\ "SysoFiles", "TestGoFiles", "XTestGoFiles"]
|
|
|
|
|
|
|
|
" Used as completion
|
|
|
|
if len(a:000) > 0
|
|
|
|
let l:list = filter(l:list, 'strpart(v:val, 0, len(a:1)) == a:1')
|
|
|
|
endif
|
|
|
|
|
|
|
|
return l:list
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#tool#Files(...) abort
|
|
|
|
if len(a:000) > 0
|
|
|
|
let source_files = a:000
|
2016-06-26 07:12:36 -04:00
|
|
|
else
|
2017-09-02 06:43:18 -04:00
|
|
|
let source_files = ['GoFiles']
|
2016-06-26 07:12:36 -04:00
|
|
|
endif
|
2017-09-02 06:43:18 -04:00
|
|
|
|
|
|
|
let combined = ''
|
|
|
|
for sf in source_files
|
|
|
|
" Strip dot in case people used ":GoFiles .GoFiles".
|
|
|
|
let sf = substitute(sf, '^\.', '', '')
|
|
|
|
|
|
|
|
" Make sure the passed options are valid.
|
|
|
|
if index(go#tool#ValidFiles(), sf) == -1
|
|
|
|
echoerr "unknown source file variable: " . sf
|
|
|
|
endif
|
|
|
|
|
|
|
|
if go#util#IsWin()
|
|
|
|
let combined .= '{{range $f := .' . sf . '}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}'
|
|
|
|
else
|
|
|
|
let combined .= "{{range $f := ." . sf . "}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}/{{$f}}{{printf \"\\n\"}}{{end}}"
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2019-03-08 06:04:56 -05:00
|
|
|
let [l:out, l:err] = go#util#ExecInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', l:combined])
|
2018-06-14 06:31:12 -04:00
|
|
|
return split(l:out, '\n')
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
2016-12-27 09:46:49 -05:00
|
|
|
function! go#tool#Deps() abort
|
2016-06-26 07:12:36 -04:00
|
|
|
if go#util#IsWin()
|
|
|
|
let format = '{{range $f := .Deps}}{{$f}}{{printf \"\n\"}}{{end}}'
|
|
|
|
else
|
|
|
|
let format = "{{range $f := .Deps}}{{$f}}\n{{end}}"
|
|
|
|
endif
|
2019-03-08 06:04:56 -05:00
|
|
|
let [l:out, l:err] = go#util#ExecInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', l:format])
|
2018-06-14 06:31:12 -04:00
|
|
|
return split(l:out, '\n')
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
2016-12-27 09:46:49 -05:00
|
|
|
function! go#tool#Imports() abort
|
2016-06-26 07:12:36 -04:00
|
|
|
let imports = {}
|
|
|
|
if go#util#IsWin()
|
|
|
|
let format = '{{range $f := .Imports}}{{$f}}{{printf \"\n\"}}{{end}}'
|
|
|
|
else
|
|
|
|
let format = "{{range $f := .Imports}}{{$f}}{{printf \"\\n\"}}{{end}}"
|
|
|
|
endif
|
2019-03-08 06:04:56 -05:00
|
|
|
let [l:out, l:err] = go#util#ExecInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', l:format])
|
2018-06-14 06:31:12 -04:00
|
|
|
if l:err != 0
|
2016-06-26 07:12:36 -04:00
|
|
|
echo out
|
|
|
|
return imports
|
|
|
|
endif
|
2014-10-31 17:30:24 -04:00
|
|
|
|
2016-06-26 07:12:36 -04:00
|
|
|
for package_path in split(out, '\n')
|
2019-03-08 06:04:56 -05:00
|
|
|
let [l:out, l:err] = go#util#ExecInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', '{{.Name}}', l:package_path])
|
2018-06-14 06:31:12 -04:00
|
|
|
if l:err != 0
|
|
|
|
echo out
|
|
|
|
return imports
|
|
|
|
endif
|
|
|
|
let package_name = substitute(l:out, '\n$', '', '')
|
2016-06-26 07:12:36 -04:00
|
|
|
let imports[package_name] = package_path
|
|
|
|
endfor
|
2014-10-31 17:30:24 -04:00
|
|
|
|
2016-06-26 07:12:36 -04:00
|
|
|
return imports
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-09-24 20:40:17 -04:00
|
|
|
function! go#tool#Info(showstatus) abort
|
2018-06-14 06:31:12 -04:00
|
|
|
let l:mode = go#config#InfoMode()
|
2016-12-27 09:46:49 -05:00
|
|
|
if l:mode == 'gocode'
|
2018-09-24 20:40:17 -04:00
|
|
|
call go#complete#Info(a:showstatus)
|
2016-12-27 09:46:49 -05:00
|
|
|
elseif l:mode == 'guru'
|
2018-09-24 20:40:17 -04:00
|
|
|
call go#guru#DescribeInfo(a:showstatus)
|
2019-05-17 10:09:13 -04:00
|
|
|
elseif l:mode == 'gopls'
|
|
|
|
call go#lsp#Info(a:showstatus)
|
2016-12-27 09:46:49 -05:00
|
|
|
else
|
2019-05-17 10:09:13 -04:00
|
|
|
call go#util#EchoError('go_info_mode value: '. l:mode .' is not valid. Valid values are: [gocode, guru, gopls]')
|
2016-12-27 09:46:49 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! go#tool#PackageName() abort
|
2019-03-08 06:04:56 -05:00
|
|
|
let [l:out, l:err] = go#util#ExecInDir(['go', 'list', '-tags', go#config#BuildTags(), '-f', '{{.Name}}'])
|
2018-06-14 06:31:12 -04:00
|
|
|
if l:err != 0
|
2016-07-03 07:53:59 -04:00
|
|
|
return -1
|
|
|
|
endif
|
|
|
|
|
|
|
|
return split(out, '\n')[0]
|
|
|
|
endfunction
|
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
" Exists checks whether the given importpath exists or not. It returns 0 if
|
|
|
|
" the importpath exists under GOPATH.
|
2016-12-27 09:46:49 -05:00
|
|
|
function! go#tool#Exists(importpath) abort
|
2019-03-08 06:04:56 -05:00
|
|
|
let [l:out, l:err] = go#util#ExecInDir(['go', 'list', a:importpath])
|
2018-06-14 06:31:12 -04:00
|
|
|
if l:err != 0
|
2014-10-31 17:30:24 -04:00
|
|
|
return -1
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
2019-03-08 06:04:56 -05:00
|
|
|
function! go#tool#DescribeBalloon()
|
2019-05-17 10:09:13 -04:00
|
|
|
let l:fname = fnamemodify(bufname(v:beval_bufnr), ':p')
|
2019-08-22 11:36:17 -04:00
|
|
|
|
|
|
|
let l:winid = win_getid()
|
|
|
|
|
|
|
|
call win_gotoid(bufwinid(v:beval_bufnr))
|
|
|
|
|
|
|
|
let [l:line, l:col] = go#lsp#lsp#Position(v:beval_lnum, v:beval_col)
|
|
|
|
call go#lsp#Hover(l:fname, l:line, l:col, funcref('s:balloon', []))
|
|
|
|
|
|
|
|
call win_gotoid(l:winid)
|
2019-05-17 10:09:13 -04:00
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:balloon(msg)
|
|
|
|
let l:msg = a:msg
|
|
|
|
if has('balloon_eval')
|
|
|
|
if has('balloon_multiline')
|
|
|
|
let l:msg = join(a:msg, "\n")
|
|
|
|
else
|
|
|
|
let l:msg = substitute(join(map(deepcopy(a:msg), 'substitute(v:val, "\t", "", "")'), '; '), '{;', '{', '')
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
call balloon_show(l:msg)
|
2014-10-31 17:30:24 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-12-17 06:28:27 -05:00
|
|
|
" restore Vi compatibility settings
|
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|
2016-06-26 07:12:36 -04:00
|
|
|
" vim: sw=2 ts=2 et
|