From 3f5645cc108738bbac68f3d5150da37910b6a157 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 1 Dec 2024 19:16:17 +1100 Subject: [PATCH] trying to find build failure --- lua/go/impl.lua | 7 ++++- lua/go/runner.lua | 64 ++++++++++++++++++++------------------ lua/tests/go_impl_spec.lua | 7 +++-- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/lua/go/impl.lua b/lua/go/impl.lua index 4929168b5..b9832dc80 100644 --- a/lua/go/impl.lua +++ b/lua/go/impl.lua @@ -108,21 +108,26 @@ local run = function(...) -- vim.cmd("normal! $%") -- do a bracket match. changed to treesitter local opts = { update_buffer = true, + loclist = false, on_exit = function(code, signal, data) if code ~= 0 or signal ~= 0 then utils.warn('impl failed' .. vim.inspect(data)) return end data = vim.split(data, '\n') - data = utils.handle_job_data(data) + log('data', data) if not data then + utils.warn('impl failed' .. vim.inspect(data)) return end vim.schedule(function() local lnum = vfn.getcurpos()[2] table.insert(data, 1, '') + vfn.setpos('.', { 0, lnum, 1, 0 }) vfn.append(lnum, data) + log('append done', lnum, data) vim.cmd('w') + log('impl done') end) end, } diff --git a/lua/go/runner.lua b/lua/go/runner.lua index e18e26421..df3c1ada9 100644 --- a/lua/go/runner.lua +++ b/lua/go/runner.lua @@ -60,10 +60,12 @@ local run = function(cmd, opts, uvopts) locopts.efm = opts.efm end log(locopts) - vim.schedule(function() - vim.fn.setloclist(0, {}, 'a', locopts) - vim.notify('run lopen to see output', vim.log.levels.INFO) - end) + if opts.setloclist ~= false then + vim.schedule(function() + vim.fn.setloclist(0, {}, 'a', locopts) + vim.notify('run lopen to see output', vim.log.levels.INFO) + end) + end end return lines end @@ -106,6 +108,8 @@ local run = function(cmd, opts, uvopts) end end + output_buf = '' + output_stderr = '' handle, _ = uv.spawn( cmd, { stdio = { stdin, stdout, stderr }, cwd = uvopts.cwd, args = job_options.args }, @@ -141,40 +145,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 + 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, combine_output) + _GO_NVIM_CFG.on_exit(code, signal, output_buf) end ) _GO_NVIM_CFG.on_jobstart(cmd) diff --git a/lua/tests/go_impl_spec.lua b/lua/tests/go_impl_spec.lua index 07c62ae75..57272efd1 100644 --- a/lua/tests/go_impl_spec.lua +++ b/lua/tests/go_impl_spec.lua @@ -22,6 +22,7 @@ describe('should run impl', function() local path = cur_dir .. '/lua/tests/fixtures/impl/impl_input.go' -- %:p:h ? %:p local lines = vim.fn.readfile(path) vim.fn.writefile(lines, name) + print('test file name:', name) local cmd = " silent exe 'e " .. name .. "'" vim.cmd(cmd) local bufn = vim.fn.bufnr('') @@ -31,10 +32,10 @@ describe('should run impl', function() require('go').setup({ verbose = true }) local goimpl = require('go.impl') goimpl.run('io.Writer') - vim.wait(400, function() end) - local impled = vim.fn.join(vim.fn.readfile(name), '\n') + vim.wait(1000, function() end) local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/impl/impl_golden.txt'), '\n') - vim.fn.assert_equal(impled, expected) + local impled = vim.fn.join(vim.fn.readfile(name), '\n') + print(vim.fn.assert_equal(impled, expected)) eq(expected, impled) vim.cmd('bd! ' .. name) end)