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

use go#util#Echo* functions consistently #2458

Merged
merged 10 commits into from
Sep 17, 2019
68 changes: 57 additions & 11 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ function! go#cmd#Build(bang, ...) abort

" Vim 7.4 without async
else
let l:status = {
\ 'desc': 'current status',
\ 'type': 'build',
\ 'state': "started",
\ }
call go#statusline#Update(expand('%:p:h'), l:status)

let default_makeprg = &makeprg
let &makeprg = "go " . join(go#util#Shelllist(args), ' ')

Expand All @@ -68,9 +75,14 @@ function! go#cmd#Build(bang, ...) abort
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
let l:status.state = 'failed'
else
call go#util#EchoSuccess("[build] SUCCESS")
let l:status.state = 'success'
if go#config#EchoCommandInfo()
call go#util#EchoSuccess("[build] SUCCESS")
endif
endif
call go#statusline#Update(expand('%:p:h'), l:status)
endif
endfunction

Expand Down Expand Up @@ -134,6 +146,14 @@ function! go#cmd#Run(bang, ...) abort
" anything. Once this is implemented we're going to make :GoRun async
endif

let l:status = {
\ 'desc': 'current status',
\ 'type': 'run',
\ 'state': "started",
\ }

call go#statusline#Update(expand('%:p:h'), l:status)

let cmd = "go run "
let tags = go#config#BuildTags()
if len(tags) > 0
Expand All @@ -147,12 +167,21 @@ function! go#cmd#Run(bang, ...) abort
exec '!' . cmd . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
endif

let l:status.state = 'success'
if v:shell_error
redraws! | echon "vim-go: [run] " | echohl ErrorMsg | echon "FAILED"| echohl None
let l:status.state = 'failed'
if go#config#EchoCommandInfo()
redraws!
call go#util#EchoError('[run] FAILED')
endif
else
redraws! | echon "vim-go: [run] " | echohl Function | echon "SUCCESS"| echohl None
if go#config#EchoCommandInfo()
redraws!
call go#util#EchoSuccess('[run] SUCCESS')
endif
endif

call go#statusline#Update(expand('%:p:h'), l:status)
return
endif

Expand All @@ -166,8 +195,8 @@ function! go#cmd#Run(bang, ...) abort

let l:listtype = go#list#Type("GoRun")

let l:status.state = 'success'
try

" backup user's errorformat, will be restored once we are finished
let l:old_errorformat = &errorformat
let &errorformat = s:runerrorformat()
Expand All @@ -185,10 +214,13 @@ function! go#cmd#Run(bang, ...) abort
let l:errors = go#list#Get(l:listtype)

call go#list#Window(l:listtype, len(l:errors))
if !empty(l:errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
if !empty(l:errors)
let l:status.state = 'failed'
if !a:bang
call go#list#JumpToFirst(l:listtype)
endif
endif

call go#statusline#Update(expand('%:p:h'), l:status)
endfunction

" Install installs the package by simple calling 'go install'. If any argument
Expand Down Expand Up @@ -255,9 +287,18 @@ function! go#cmd#Generate(bang, ...) abort
let &makeprg = "go generate " . goargs . ' ' . gofiles
endif

let l:listtype = go#list#Type("GoGenerate")
let l:status = {
\ 'desc': 'current status',
\ 'type': 'generate',
\ 'state': "started",
\ }
call go#statusline#Update(expand('%:p:h'), l:status)

echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
if go#config#EchoCommandInfo()
call go#util#EchoProgress('generating ...')
endif

let l:listtype = go#list#Type("GoGenerate")

try
if l:listtype == "locationlist"
Expand All @@ -273,13 +314,18 @@ function! go#cmd#Generate(bang, ...) abort
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
let l:status.status = 'failed'
if !a:bang
call go#list#JumpToFirst(l:listtype)
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
let l:status.status = 'success'
if go#config#EchoCommandInfo()
redraws!
call go#util#EchoSuccess('[generate] SUCCESS')
endif
endif

call go#statusline#Update(expand(':%:p:h'), l:status)
endfunction

function! s:runerrorformat()
Expand Down
1 change: 0 additions & 1 deletion autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ function! s:info_complete(echo, result) abort
endfunction

function! s:trim_bracket(val) abort
echom a:val
let a:val.word = substitute(a:val.word, '[(){}\[\]]\+$', '', '')
return a:val
endfunction
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ endfunction

function! s:call_jsonrpc(method, ...) abort
if go#util#HasDebug('debugger-commands')
echom 'sending to dlv ' . a:method
call go#util#EchoInfo('sending to dlv ' . a:method)
endif

let l:args = a:000
Expand Down
1 change: 0 additions & 1 deletion autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function! s:show_errors(errors) abort
let l:listtype = go#list#Type("GoFmt")
if !empty(a:errors)
call go#list#Populate(l:listtype, a:errors, 'Format')
echohl Error | echomsg "Gofmt returned error" | echohl None
endif

" this closes the window if there are no errors or it opens
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function! go#lint#Gometa(bang, autosave, ...) abort

if l:err == 0
call go#list#Clean(l:listtype)
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
call go#util#EchoSuccess('[metalinter] PASS')
else
let l:winid = win_getid(winnr())
" Parse and populate our location list
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/package.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function! s:paths() abort
if executable('go')
let s:goroot = go#util#env("goroot")
if go#util#ShellError() != 0
echomsg '''go env GOROOT'' failed'
call go#util#EchoError('`go env GOROOT` failed')
endif
else
let s:goroot = $GOROOT
Expand Down
4 changes: 2 additions & 2 deletions autoload/go/path.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ function! go#path#GoPath(...) abort
let s:initial_go_path = ""
endif

echon "vim-go: " | echohl Function | echon "GOPATH restored to ". $GOPATH | echohl None
call go#util#EchoInfo("GOPATH restored to ". $GOPATH)
return
endif

echon "vim-go: " | echohl Function | echon "GOPATH changed to ". a:1 | echohl None
call go#util#EchoInfo("GOPATH changed to ". a:1)
let s:initial_go_path = $GOPATH
let $GOPATH = a:1
endfunction
Expand Down
7 changes: 3 additions & 4 deletions autoload/go/play.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set cpo&vim

function! go#play#Share(count, line1, line2) abort
if !executable('curl')
echohl ErrorMsg | echomsg "vim-go: require 'curl' command" | echohl None
call go#util#EchoError('cannot share: curl cannot be found')
return
endif

Expand All @@ -20,8 +20,7 @@ function! go#play#Share(count, line1, line2) abort
call delete(share_file)

if l:err != 0
echom 'A error has occurred. Run this command to see what the problem is:'
echom go#util#Shelljoin(l:cmd)
call go#util#EchoError(['A error has occurred. Run this command to see what the problem is:', go#util#Shelljoin(l:cmd)])
return
endif

Expand All @@ -38,7 +37,7 @@ function! go#play#Share(count, line1, line2) abort
call go#util#OpenBrowser(url)
endif

echo "vim-go: snippet uploaded: ".url
call go#util#EchoInfo('snippet uploaded: ' . url)
endfunction


Expand Down
14 changes: 6 additions & 8 deletions plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ function! s:GoInstallBinaries(updateBinaries, ...)
endif

if go#path#Default() == ""
echohl Error
echomsg "vim.go: $GOPATH is not set and 'go env GOPATH' returns empty"
echohl None
call go#util#EchoError('$GOPATH is not set and `go env GOPATH` returns empty')
return
endif

Expand Down Expand Up @@ -176,7 +174,7 @@ function! s:GoInstallBinaries(updateBinaries, ...)
" first download the binary
let [l:out, l:err] = go#util#Exec(l:get_cmd + [l:importPath])
if l:err
echom "Error installing " . l:importPath . ": " . l:out
call go#util#EchoError(printf('Error installing %s: %s', l:importPath, l:out))
endif

call call(Restore_modules, [])
Expand All @@ -197,7 +195,7 @@ function! s:GoInstallBinaries(updateBinaries, ...)
" first download the binary
let [l:out, l:err] = go#util#Exec(l:get_cmd + [l:importPath])
if l:err
echom "Error downloading " . l:importPath . ": " . l:out
call go#util#EchoError(printf('Error downloading %s: %s', l:importPath, l:out))
endif

" and then build and install it
Expand All @@ -208,7 +206,7 @@ function! s:GoInstallBinaries(updateBinaries, ...)

let [l:out, l:err] = go#util#Exec(l:build_cmd)
if l:err
echom "Error installing " . l:importPath . ": " . l:out
call go#util#EchoError(printf('Error installing %s: %s', l:importPath, l:out))
endif


Expand Down Expand Up @@ -241,12 +239,12 @@ endfunction
" commands are available.
function! s:CheckBinaries()
if !executable('go')
echohl Error | echomsg "vim-go: go executable not found." | echohl None
call go#util#EchoError('go executable not found.')
return -1
endif

if !executable('git')
echohl Error | echomsg "vim-go: git executable not found." | echohl None
call go#util#EchoError('git executable not found.')
return -1
endif
endfunction
Expand Down