Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set GO111MODULE=off when installing tools #2253

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions autoload/go/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,37 @@ function! go#util#ShowInfo(info)
echo "vim-go: " | echohl Function | echon a:info | echohl None
endfunction

" go#util#SetEnv takes the name of an environment variable and what its value
" should be and returns a function that will restore it to its original value.
function! go#util#SetEnv(name, value) abort
let l:state = {}

if len(a:name) == 0
return function('s:noop', [], l:state)
endif

let l:remove = 0
if exists('$' . a:name)
let l:oldvalue = eval('$' . a:name)
else
let l:remove = 1
endif

call execute('let $' . a:name . ' = "' . a:value . '"')

if l:remove
function! s:remove(name) abort
call execute('unlet $' . a:name)
endfunction
return function('s:remove', [a:name], l:state)
endif

return function('go#util#SetEnv', [a:name, l:oldvalue], l:state)
endfunction

function! s:noop(...) abort dict
endfunction

" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
Expand Down
12 changes: 7 additions & 5 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ function! s:GoInstallBinaries(updateBinaries, ...)
" change $GOBIN so go get can automatically install to it
let $GOBIN = go_bin_path

" old_path is used to restore users own path
let old_path = $PATH

" vim's executable path is looking in PATH so add our go_bin path to it
let $PATH = go_bin_path . go#util#PathListSep() . $PATH
let Restore_path = go#util#SetEnv('PATH', go_bin_path . go#util#PathListSep() . $PATH)

" GO111MODULE must be off to install golanci-lint and gometalinter
let Restore_modules = go#util#SetEnv('GO111MODULE', 'off')

" when shellslash is set on MS-* systems, shellescape puts single quotes
" around the output string. cmd on Windows does not handle single quotes
Expand Down Expand Up @@ -185,7 +185,9 @@ function! s:GoInstallBinaries(updateBinaries, ...)
endfor

" restore back!
let $PATH = old_path
call call(Restore_path, [])
call call(Restore_modules, [])

if resetshellslash
set shellslash
endif
Expand Down