diff --git a/lua/go/runner.lua b/lua/go/runner.lua index 4ee287964..509d527ca 100644 --- a/lua/go/runner.lua +++ b/lua/go/runner.lua @@ -108,6 +108,7 @@ local run = function(cmd, opts, uvopts) end end + output_stderr = '' handle, _ = uv.spawn( cmd, { stdio = { stdin, stdout, stderr }, cwd = uvopts.cwd, args = job_options.args }, @@ -143,40 +144,40 @@ local run = function(cmd, opts, uvopts) end) end - -- stdout was handled by update_chunk - -- lets handle stderr here - if output_stderr ~= '' then + local combine_output = '' + if output_buf ~= '' or output_stderr ~= '' then -- some commands may output to stderr instead of stdout - output_stderr = util.remove_ansi_escape(output_stderr) - output_stderr = vim.trim(output_stderr) - log('output_stderr', output_stderr) - - local lines = util.handle_job_data(vim.split(output_stderr, '\n')) - if #lines > 0 then - vim.schedule(function() - local locopts = { - title = vim.inspect(cmd), - efm = opts.efm, - lines = lines, - } - - log('job data lines:', locopts) - vim.fn.setloclist(0, {}, 'a', locopts) - end) - end + combine_output = (output_buf or '') .. '\n' .. (output_stderr or '') + combine_output = util.remove_ansi_escape(combine_output) + combine_output = vim.trim(combine_output) end - - local combine_output = output_buf .. '\n' .. output_stderr if opts and opts.on_exit then local onexit_output = opts.on_exit(code, signal, combine_output) - log('on_exit returned ', onexit_output) + if not onexit_output then + return + else + combine_output = onexit_output + end end if code ~= 0 or signal ~= 0 or output_stderr ~= '' then - log('command finished with error code: ', code, signal) + local lines = util.handle_job_data(vim.split(combine_output, '\n')) + local locopts = { + title = vim.inspect(cmd), + lines = lines, + } + if opts.efm then + locopts.efm = opts.efm end - - _GO_NVIM_CFG.on_exit(code, signal, combine_output) + log('command finished: ', locopts, lines) + if #lines > 0 then + vim.schedule(function() + vim.fn.setloclist(0, {}, ' ', locopts) + util.info('run lopen to see output') + end) + end + end + _GO_NVIM_CFG.on_exit(code, signal, output_buf) end ) _GO_NVIM_CFG.on_jobstart(cmd)