Skip to content

Commit

Permalink
Merge pull request #1320 from fatih/cache-env-calls
Browse files Browse the repository at this point in the history
Improve caching for go env calls
  • Loading branch information
fatih authored Jun 6, 2017
2 parents 52e5ad5 + b0a11f0 commit bc097c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions autoload/go/impl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ endif

function! s:root_dirs() abort
let dirs = []
let root = go#util#goroot()
let root = go#util#env("goroot")
if root !=# '' && isdirectory(root)
call add(dirs, root)
endif

let paths = map(split(go#util#gopath(), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
let paths = map(split(go#util#env("gopath"), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
if go#util#ShellError()
return []
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/package.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function! go#package#Paths() abort

if !exists("s:goroot")
if executable('go')
let s:goroot = go#util#goroot()
let s:goroot = go#util#env("goroot")
if go#util#ShellError() != 0
echomsg '''go env GOROOT'' failed'
endif
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ endfunction
function! go#path#Default() abort
if $GOPATH == ""
" use default GOPATH via go env
return go#util#gopath()
return go#util#env("gopath")
endif

return $GOPATH
Expand Down
10 changes: 9 additions & 1 deletion autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,32 @@ function! go#util#env(key) abort
return l:var
endfunction

" goarch returns 'go env GOARCH'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("goarch")'
function! go#util#goarch() abort
return substitute(go#util#System('go env GOARCH'), '\n', '', 'g')
endfunction

" goos returns 'go env GOOS'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("goos")'
function! go#util#goos() abort
return substitute(go#util#System('go env GOOS'), '\n', '', 'g')
endfunction

" goroot returns 'go env GOROOT'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("goroot")'
function! go#util#goroot() abort
return substitute(go#util#System('go env GOROOT'), '\n', '', 'g')
endfunction

" gopath returns 'go env GOPATH'. This is an internal function and shouldn't
" be used. Instead use 'go#util#env("gopath")'
function! go#util#gopath() abort
return substitute(go#util#System('go env GOPATH'), '\n', '', 'g')
endfunction

function! go#util#osarch() abort
return go#util#goos() . '_' . go#util#goarch()
return go#util#env("goos") . '_' . go#util#env("goarch")
endfunction

" System runs a shell command. If possible, it will temporary set
Expand Down

0 comments on commit bc097c1

Please sign in to comment.