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

fix :GoBuild issues in neovim #1176

Merged
merged 1 commit into from
Feb 2, 2017
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
5 changes: 4 additions & 1 deletion autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ function! go#cmd#Build(bang, ...) abort
\})
return
elseif has('nvim')
if get(g:, 'go_echo_command_info', 1)
call go#util#EchoProgress("building dispatched ...")
endif

" if we have nvim, call it asynchronously and return early ;)
call go#util#EchoProgress("building dispatched ...")
call go#jobcontrol#Spawn(a:bang, "build", args)
return
endif
Expand Down
44 changes: 40 additions & 4 deletions autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ endfunction
" GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the
" current files folder.
function! s:spawn(bang, desc, args) abort
let status_type = a:args[0]
let status_dir = expand('%:p:h')
let started_at = reltime()

call go#statusline#Update(status_dir, {
\ 'desc': "current status",
\ 'type': status_type,
\ 'state': "started",
\})

let job = {
\ 'desc': a:desc,
\ 'bang': a:bang,
Expand All @@ -49,6 +59,9 @@ function! s:spawn(bang, desc, args) abort
\ 'on_stdout': function('s:on_stdout'),
\ 'on_stderr': function('s:on_stderr'),
\ 'on_exit' : function('s:on_exit'),
\ 'status_type' : status_type,
\ 'status_dir' : status_dir,
\ 'started_at' : started_at,
\ }

" modify GOPATH if needed
Expand Down Expand Up @@ -91,6 +104,23 @@ endfunction
" on_stderr handler. If there are no errors and a quickfix window is open,
" it'll be closed.
function! s:on_exit(job_id, exit_status, event) dict abort
let status = {
\ 'desc': 'last status',
\ 'type': self.status_type,
\ 'state': "success",
\ }

if a:exit_status
let status.state = "failed"
endif

let elapsed_time = reltimestr(reltime(self.started_at))
" strip whitespace
let elapsed_time = substitute(elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '')
let status.state .= printf(" (%ss)", elapsed_time)

call go#statusline#Update(self.status_dir, status)

let std_combined = self.stderr + self.stdout

let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -105,14 +135,20 @@ function! s:on_exit(job_id, exit_status, event) dict abort
call go#list#Window(l:listtype)

let self.state = "SUCCESS"
call go#util#EchoSuccess("SUCCESS")

if get(g:, 'go_echo_command_info', 1)
call go#util#EchoSuccess("[" . self.status_type . "] SUCCESS")
endif

execute cd . fnameescape(dir)
return
endif

let self.state = "FAILED"
call go#util#EchoError("FAILED")

if get(g:, 'go_echo_command_info', 1)
call go#util#EchoError("[" . self.status_type . "] FAILED")
endif

let errors = go#tool#ParseErrors(std_combined)
let errors = go#tool#FilterValids(errors)
Expand Down Expand Up @@ -148,13 +184,13 @@ endfunction

" on_stdout is the stdout handler for jobstart(). It collects the output of
" stderr and stores them to the jobs internal stdout list.
function! s:on_stdout(job_id, data) dict abort
function! s:on_stdout(job_id, data, event) dict abort
call extend(self.stdout, a:data)
endfunction

" on_stderr is the stderr handler for jobstart(). It collects the output of
" stderr and stores them to the jobs internal stderr list.
function! s:on_stderr(job_id, data) dict abort
function! s:on_stderr(job_id, data, event) dict abort
call extend(self.stderr, a:data)
endfunction

Expand Down