Skip to content

Commit

Permalink
use go#util#system(), go#util#shell_errors() instead of system(), v:s…
Browse files Browse the repository at this point in the history
…hell_error (#801)

* use go#util#system(), go#util#shell_errors() instead of system(), v:shell_error

NOTE: except bang command like "!go run"
  • Loading branch information
mattn authored and fatih committed Apr 26, 2016
1 parent e9df17f commit f830d0d
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 115 deletions.
4 changes: 2 additions & 2 deletions autoload/ctrlp/decls.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function! ctrlp#decls#enter()
let command .= printf(" -dir %s", dir)
endif

let out = system(command)
if v:shell_error != 0
let out = go#util#System(command)
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
endif
Expand Down
4 changes: 2 additions & 2 deletions autoload/go/asmfmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function! go#asmfmt#Format()
if empty(path)
return
endif
let out = system(path . ' -w ' . l:tmpname)
let out = go#util#System(path . ' -w ' . l:tmpname)

" If there's no error, replace the current file with the output.
if v:shell_error == 0
if go#util#ShellError() != 0
" Remove undo point caused by BufWritePre.
try | silent undojoin | catch | endtry

Expand Down
4 changes: 2 additions & 2 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function! go#cmd#Test(bang, compile, ...)

let l:listtype = "quickfix"

if v:shell_error
if go#util#ShellError() != 0
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
try
Expand Down Expand Up @@ -299,7 +299,7 @@ function! go#cmd#Generate(bang, ...)

" :make expands '%' and '#' wildcards, so they must also be escaped
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
if v:shell_error
if go#util#ShellError() != 0
let &makeprg = "go generate " . goargs
else
let gofiles = go#util#Shelljoin(go#tool#Files(), 1)
Expand Down
40 changes: 4 additions & 36 deletions autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,12 @@ fu! s:gocodeCurrentBuffer()
return file
endf

if go#vimproc#has_vimproc()
let s:vim_system = get(g:, 'gocomplete#system_function', 'vimproc#system2')
let s:vim_shell_error = get(g:, 'gocomplete#shell_error_function', 'vimproc#get_last_status')
else
let s:vim_system = get(g:, 'gocomplete#system_function', 'system')
let s:vim_shell_error = ''
endif

fu! s:shell_error()
if empty(s:vim_shell_error)
return v:shell_error
endif
return call(s:vim_shell_error, [])
endf

fu! s:system(str, ...)
return call(s:vim_system, [a:str] + a:000)
endf

fu! s:gocodeShellescape(arg)
if go#vimproc#has_vimproc()
return vimproc#shellescape(a:arg)
endif
try
let ssl_save = &shellslash
set noshellslash
return shellescape(a:arg)
finally
let &shellslash = ssl_save
endtry
endf

fu! s:gocodeCommand(cmd, preargs, args)
for i in range(0, len(a:args) - 1)
let a:args[i] = s:gocodeShellescape(a:args[i])
let a:args[i] = go#util#Shellescape(a:args[i])
endfor
for i in range(0, len(a:preargs) - 1)
let a:preargs[i] = s:gocodeShellescape(a:preargs[i])
let a:preargs[i] = go#util#Shellescape(a:preargs[i])
endfor

let bin_path = go#path#CheckBinPath(g:go_gocode_bin)
Expand All @@ -69,11 +37,11 @@ fu! s:gocodeCommand(cmd, preargs, args)
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()

let result = s:system(printf('%s %s %s %s', s:gocodeShellescape(bin_path), join(a:preargs), s:gocodeShellescape(a:cmd), join(a:args)))
let result = go#util#System(printf('%s %s %s %s', go#util#Shellescape(bin_path), join(a:preargs), go#util#Shellescape(a:cmd), join(a:args)))

let $GOPATH = old_gopath

if s:shell_error() != 0
if go#util#ShellError() != 0
return "[\"0\", []]"
else
if &encoding != 'utf-8'
Expand Down
8 changes: 4 additions & 4 deletions autoload/go/coverage.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function! go#coverage#Buffer(bang, ...)
endif

let s:toggle = 1
let l:tmpname=tempname()
let l:tmpname = tempname()
let args = [a:bang, 0, "-coverprofile", l:tmpname]

if a:0
Expand All @@ -54,7 +54,7 @@ function! go#coverage#Buffer(bang, ...)
return
endif

if !v:shell_error
if go#util#ShellError() != 0
call go#coverage#overlay(l:tmpname)
endif

Expand All @@ -78,7 +78,7 @@ endfunction
" Browser creates a new cover profile with 'go test -coverprofile' and opens
" a new HTML coverage page from that profile in a new browser
function! go#coverage#Browser(bang, ...)
let l:tmpname=tempname()
let l:tmpname = tempname()
let args = [a:bang, 0, "-coverprofile", l:tmpname]

if a:0
Expand All @@ -90,7 +90,7 @@ function! go#coverage#Browser(bang, ...)
let s:coverage_browser_handler_jobs[id] = l:tmpname
return
endif
if !v:shell_error
if go#util#ShellError() != 0
let openHTML = 'go tool cover -html='.l:tmpname
call go#tool#ExecuteInDir(openHTML)
endif
Expand Down
14 changes: 2 additions & 12 deletions autoload/go/def.vim
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
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

let s:go_stack = []
let s:go_stack_level = 0

Expand All @@ -23,8 +13,8 @@ function! go#def#Jump(mode)
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
let command = printf("%s definition %s:#%s", bin_path, shellescape(fname), go#util#OffsetCursor())

let out = s:system(command)
if !v:shell_error == 0
let out = go#util#System(command)
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
endif
Expand Down
4 changes: 2 additions & 2 deletions autoload/go/doc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ function! go#doc#Open(newmode, mode, ...)

let command = printf("%s -pos %s:#%s", bin_path, fname, offset)

let out = system(command)
if v:shell_error != 0
let out = go#util#System(command)
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
endif
Expand Down
15 changes: 9 additions & 6 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ function! go#fmt#Format(withGoimport)
try
mkview!
catch
let l:curw=winsaveview()
let l:curw = winsaveview()
endtry
else
" Save cursor position and many other things.
let l:curw=winsaveview()
let l:curw = winsaveview()
endif

" Write current unsaved buffer to a temp file
Expand All @@ -81,7 +81,7 @@ function! go#fmt#Format(withGoimport)
" prevent an additional undo jump due to BufWritePre auto command and also
" restore 'redo' history because it's getting being destroyed every
" BufWritePre
let tmpundofile=tempname()
let tmpundofile = tempname()
exe 'wundo! ' . tmpundofile
endif

Expand Down Expand Up @@ -115,7 +115,7 @@ function! go#fmt#Format(withGoimport)

if fmt_command == "goimports"
if !exists('b:goimports_vendor_compatible')
let out = system("goimports --help")
let out = go#util#System("goimports --help")
if out !~ "-srcdir"
echohl WarningMsg
echomsg "vim-go: goimports does not support srcdir."
Expand All @@ -135,7 +135,10 @@ function! go#fmt#Format(withGoimport)
endif

" execute our command...
let out = system(command . " " . l:tmpname)
if go#util#IsWin()
let l:tmpname = tr(l:tmpname, '\', '/')
endif
let out = go#util#System(command . " " . l:tmpname)

if fmt_command != "gofmt"
let $GOPATH = old_gopath
Expand All @@ -145,7 +148,7 @@ function! go#fmt#Format(withGoimport)
"if there is no error on the temp file replace the output with the current
"file (if this fails, we can always check the outputs first line with:
"splitted =~ 'package \w\+')
if v:shell_error == 0
if go#util#ShellError() == 0
" remove undo point caused via BufWritePre
try | silent undojoin | catch | endtry

Expand Down
4 changes: 2 additions & 2 deletions autoload/go/guru.vim
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
call go#util#EchoProgress("analysing ...")

" run, forrest run!!!
let out = system(command)
let out = go#util#System(command)

let $GOPATH = old_gopath

if v:shell_error
if go#util#ShellError() != 0
" unfortunaly guru outputs a very long stack trace that is not
" parsable to show the real error. But the main issue is usually the
" package which doesn't build.
Expand Down
4 changes: 2 additions & 2 deletions autoload/go/import.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function! go#import#SwitchImport(enabled, localname, path, bang)
endif

if a:bang == "!"
let out = system("go get -u -v ".shellescape(path))
if v:shell_error
let out = go#util#System("go get -u -v ".shellescape(path))
if go#util#ShellError() != 0
call s:Error("Can't find import: " . path . ":" . out)
endif
endif
Expand Down
8 changes: 4 additions & 4 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function! go#lint#Gometa(autosave, ...) abort
let out = go#tool#ExecuteInDir(meta_command)

let l:listtype = "quickfix"
if v:shell_error == 0
if go#util#ShellError() != 0
redraw | echo
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
Expand Down Expand Up @@ -102,7 +102,7 @@ function! go#lint#Golint(...) abort
let goargs = go#util#Shelljoin(a:000)
endif

let out = system(bin_path . " " . goargs)
let out = go#util#System(bin_path . " " . goargs)
if empty(out)
echon "vim-go: " | echohl Function | echon "[lint] PASS" | echohl None
return
Expand All @@ -127,7 +127,7 @@ function! go#lint#Vet(bang, ...)
endif

let l:listtype = "quickfix"
if v:shell_error
if go#util#ShellError() != 0
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
Expand Down Expand Up @@ -167,7 +167,7 @@ function! go#lint#Errcheck(...) abort
let out = go#tool#ExecuteInDir(command)

let l:listtype = "quickfix"
if v:shell_error
if go#util#ShellError() != 0
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"

" Parse and populate our location list
Expand Down
8 changes: 4 additions & 4 deletions autoload/go/package.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function! go#package#Paths()

if !exists("s:goroot")
if executable('go')
let s:goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
if v:shell_error
let s:goroot = substitute(go#util#System('go env GOROOT'), '\n', '', 'g')
if go#util#ShellError() != 0
echomsg '''go env GOROOT'' failed'
endif
else
Expand Down Expand Up @@ -95,8 +95,8 @@ function! go#package#FromPath(arg)
endfunction

function! go#package#CompleteMembers(package, member)
silent! let content = system('godoc ' . a:package)
if v:shell_error || !len(content)
silent! let content = go#util#System('godoc ' . a:package)
if go#util#ShellError() || !len(content)
return []
endif
let lines = filter(split(content, "\n"),"v:val !~ '^\\s\\+$'")
Expand Down
6 changes: 3 additions & 3 deletions autoload/go/play.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ function! go#play#Share(count, line1, line2)
call writefile(split(content, "\n"), share_file, "b")

let command = "curl -s -X POST http://play.golang.org/share --data-binary '@".share_file."'"
let snippet_id = system(command)
let snippet_id = go#util#System(command)

" we can remove the temp file because it's now posted.
call delete(share_file)

if v:shell_error
if go#util#ShellError() != 0
echo 'A error has occured. Run this command to see what the problem is:'
echo command
return
Expand Down Expand Up @@ -77,7 +77,7 @@ function! s:get_browser_command()
if go_play_browser_command == ''
if has('win32') || has('win64')
let go_play_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
elseif has('mac') || has('macunix') || has('gui_macvim') || go#util#System('uname') =~? '^darwin'
let go_play_browser_command = 'open %URL%'
elseif executable('xdg-open')
let go_play_browser_command = 'xdg-open %URL%'
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function! go#rename#Rename(bang, ...)
let clean = split(out, '\n')

let l:listtype = "quickfix"
if v:shell_error
if go#util#ShellError() != 0
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
Expand Down
8 changes: 4 additions & 4 deletions autoload/go/textobj.vim
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function! go#textobj#Function(mode)
let command .= " -parse-comments"
endif

let out = system(command)
if v:shell_error != 0
let out = go#util#System(command)
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
endif
Expand Down Expand Up @@ -129,8 +129,8 @@ function! go#textobj#FunctionJump(mode, direction)
let command .= " -parse-comments"
endif

let out = system(command)
if v:shell_error != 0
let out = go#util#System(command)
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
endif
Expand Down
Loading

0 comments on commit f830d0d

Please sign in to comment.