Skip to content

Commit

Permalink
trying to find build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Dec 1, 2024
1 parent 000a5a9 commit 3f5645c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
7 changes: 6 additions & 1 deletion lua/go/impl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
64 changes: 34 additions & 30 deletions lua/go/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lua/tests/go_impl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand All @@ -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)
Expand Down

0 comments on commit 3f5645c

Please sign in to comment.