Skip to content

Commit

Permalink
Merge pull request #3207 from bhcleek/path/gobin
Browse files Browse the repository at this point in the history
source GOBIN from go env GOBIN
  • Loading branch information
bhcleek committed Apr 28, 2021
2 parents 8852435 + f880367 commit 2bdb629
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
23 changes: 12 additions & 11 deletions autoload/go/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,25 @@ endfunction

" BinPath returns the binary path of installed go tools.
function! go#path#BinPath() abort
let bin_path = go#config#BinPath()
if bin_path != ""
return bin_path
let l:bin_path = go#config#BinPath()
if l:bin_path isnot ""
return l:bin_path
endif

" check if our global custom path is set, if not check if $GOBIN is set so
" check if our global custom path is set, if not check if GOBIN is set so
" we can use it, otherwise use default GOPATH
if $GOBIN != ""
let bin_path = $GOBIN
let l:bin_path = go#util#env('gobin')
if l:bin_path isnot ''
let l:bin_path = $GOBIN
else
let go_paths = split(go#path#Default(), go#util#PathListSep())
if len(go_paths) == 0
return "" "nothing found
let l:go_paths = split(go#path#Default(), go#util#PathListSep())
if len(l:go_paths) == 0
return '' "nothing found
endif
let bin_path = expand(go_paths[0] . "/bin/")
let l:bin_path = expand(l:go_paths[0] . '/bin/')
endif

return bin_path
return l:bin_path
endfunction

" CheckBinPath checks whether the given binary exists or not and returns the
Expand Down
19 changes: 13 additions & 6 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,32 @@ function! go#util#env(key) abort
return l:var
endfunction

" gobin returns 'go env GOBIN'. This is an internal function and shouldn't be
" used. Use go#util#env('gobin') instead.
function! go#util#gobin() abort
return substitute(s:exec(['go', 'env', 'GOBIN'])[0], '\n', '', 'g')
endfunction

" goarch returns 'go env GOARCH'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("goarch")'
" be used. Use go#util#env('goarch') instead.
function! go#util#goarch() abort
return substitute(s:exec(['go', 'env', 'GOARCH'])[0], '\n', '', 'g')
endfunction

" goos returns 'go env GOOS'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("goos")'
" goos returns 'go env GOOS'. This is an internal function and shouldn't be
" used. Use go#util#env('goos') instead.
function! go#util#goos() abort
return substitute(s:exec(['go', 'env', 'GOOS'])[0], '\n', '', 'g')
endfunction

" goroot returns 'go env GOROOT'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("goroot")'
" be used. Use go#util#env('goroot') instead.
function! go#util#goroot() abort
return substitute(s:exec(['go', 'env', 'GOROOT'])[0], '\n', '', 'g')
endfunction

" gopath returns 'go env GOPATH'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("gopath")'
" be used. Use go#util#env('gopath') instead.
function! go#util#gopath() abort
return substitute(s:exec(['go', 'env', 'GOPATH'])[0], '\n', '', 'g')
endfunction
Expand All @@ -120,7 +126,8 @@ function! go#util#gomod() abort
return substitute(s:exec(['go', 'env', 'GOMOD'])[0], '\n', '', 'g')
endfunction

" gomodcache returns 'go env GOMODCACHE'. Instead use 'go#util#env("gomodcache")'
" gomodcache returns 'go env GOMODCACHE'. Use go#util#env('gomodcache')
" instead.
function! go#util#gomodcache() abort
return substitute(s:exec(['go', 'env', 'GOMODCACHE'])[0], '\n', '', 'g')
endfunction
Expand Down
2 changes: 1 addition & 1 deletion doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ their mapping variants that cause splits. By default it's disabled. >
*'g:go_bin_path'*

Use this option to change default path for vim-go tools when using
|:GoInstallBinaries| and |:GoUpdateBinaries|. If not set `$GOBIN` or
|:GoInstallBinaries| and |:GoUpdateBinaries|. If not set `go env GOBIN` or
`$GOPATH/bin` is used. >
let g:go_bin_path = ""
Expand Down

0 comments on commit 2bdb629

Please sign in to comment.