Skip to content

Commit

Permalink
cmd: set statusline for commands (mostly Vim 7.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhcleek committed Aug 20, 2019
1 parent 2d701db commit 4f22b83
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 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,14 +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!
call go#util#EchoError('[run] FAILED')
let l:status.state = 'failed'
if go#config#EchoCommandInfo()
redraws!
call go#util#EchoError('[run] FAILED')
endif
else
redraws!
call go#util#EchoSuccess('[run] SUCCESS')
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 @@ -168,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 @@ -187,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 @@ -257,12 +287,19 @@ 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)

if go#config#EchoCommandInfo()
call go#util#EchoProgress('generating ...')
endif

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

try
if l:listtype == "locationlist"
silent! exe 'lmake!'
Expand All @@ -277,14 +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!
call go#util#EchoSuccess('[generate] SUCCESS')
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

0 comments on commit 4f22b83

Please sign in to comment.