allow show stderr from runner

pull/308/head
ray-x 1 year ago
parent 49929db247
commit edf61c77e1

@ -393,8 +393,13 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)
end
if optarg['n'] then
table.insert(cmd, '-n')
table.insert(cmd, (optarg['n'] or '1'))
if run_in_floaterm then
table.insert(cmd, '-count')
table.insert(cmd, (optarg['n'] or '1'))
else
table.insert(cmd, '-n')
table.insert(cmd, (optarg['n'] or '1'))
end
end
if optarg['C'] then
@ -472,7 +477,10 @@ M.test_func = function(...)
local parser_path = vim.api.nvim_get_runtime_file('parser' .. sep .. 'go.so', false)[1]
if not parser_path then
-- require('nvim-treesitter.install').commands.TSInstallSync['run!']('go')
vim.notify('go treesitter parser not found, please Run `:TSInstallSync go`', vim.log.levels.WARN)
vim.notify(
'go treesitter parser not found, please Run `:TSInstallSync go`',
vim.log.levels.WARN
)
end
return run_tests_with_ts_node(args, ns)
end
@ -503,7 +511,9 @@ M.get_test_cases = function()
-- utils.log(args)
local tests = M.get_testfunc()
if not tests then
local cmd = [[cat ]] .. fpath .. [[| sed -n 's/func\s\+\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\|/g']]
local cmd = [[cat ]]
.. fpath
.. [[| sed -n 's/func\s\+\(Test.*\)(.*/\1/p' | xargs | sed 's/ /\\|/g']]
-- TODO maybe with treesitter or lsp list all functions in current file and regex with Test
if vfn.executable('sed') == 0 then
return
@ -651,7 +661,9 @@ M.get_testfunc = function()
-- Note: the buffer may not be loaded yet
local ok, parser = pcall(vim.treesitter.get_parser, bufnr)
if not ok or not parser then return end
if not ok or not parser then
return
end
local tree = parser:parse()
tree = tree[1]
local query = vim.treesitter.parse_query('go', require('go.ts.go').query_test_func)

@ -157,7 +157,7 @@ local function handler()
log(diags)
if #diags > 0 or test_failed then
vim.schedule (function()
vim.schedule(function()
vim.notify('go test failed: ' .. '\n please check quickfix!\n', vim.log.levels.WARN)
end)()
end
@ -231,7 +231,7 @@ return {
end
local msgs = msg.output
msgs = vim.split(msgs, '\n', true)
msgs = vim.split(msgs, '\n', {})
-- the output is jsonencoded

@ -49,7 +49,7 @@ local run = function(cmd, opts)
output_buf = output_buf .. '\n' .. table.concat(lines, '\n')
log(lines)
local cfixlines = vim.split(output_buf, '\n', true)
local cfixlines = vim.split(output_buf, '\n')
local locopts = {
title = vim.inspect(cmd),
lines = cfixlines,
@ -85,13 +85,13 @@ local run = function(cmd, opts)
sprite = Sprite:new({
loc = 'top_center',
syntax = 'lua',
rect = { height = 1, width = 30},
data = { 'Running '.. vim.inspect(cmd) },
rect = { height = 1, width = 30 },
data = { 'Running ' .. vim.inspect(cmd) },
timeout = 30000,
hl_line = 1,
})
else
sprite = {on_close = function() end}
sprite = { on_close = function() end }
end
handle, _ = uv.spawn(
cmd,
@ -106,7 +106,7 @@ local run = function(cmd, opts)
stderr:close()
handle:close()
log("spawn finished", code, signal)
log('spawn finished', code, signal)
sprite.on_close()
if output_stderr ~= '' then
@ -126,13 +126,17 @@ local run = function(cmd, opts)
log('failed to run', code, output_buf)
output_buf = output_buf or ''
vim.schedule( function()
vim.notify(cmd_str .. ' failed exit code ' .. tostring(code) .. output_buf, vim.log.levels.WARN)
vim.schedule(function()
vim.notify(
cmd_str .. ' failed exit code ' .. tostring(code) .. output_buf,
vim.log.levels.WARN
)
end)
end
if output_buf ~= '' then
local lines = vim.split(output_buf, '\n', true)
if output_buf ~= '' or output_stderr ~= '' then
local l = (output_buf or '') .. '\n' .. (output_stderr or '')
local lines = vim.split(vim.trim(l), '\n')
lines = util.handle_job_data(lines)
local locopts = {
title = vim.inspect(cmd),
@ -141,9 +145,8 @@ local run = function(cmd, opts)
if opts.efm then
locopts.efm = opts.efm
end
log(locopts)
log(locopts, lines)
if #lines > 0 then
log(lines)
vim.schedule(function()
vim.fn.setloclist(0, {}, ' ', locopts)
util.quickfix('lopen')
@ -155,7 +158,6 @@ local run = function(cmd, opts)
)
_GO_NVIM_CFG.on_jobstart(cmd)
uv.read_start(stderr, function(err, data)
if err then
vim.notify('error ' .. tostring(err) .. tostring(data or ''), vim.log.levels.WARN)

Loading…
Cancel
Save