Skip to content

Commit

Permalink
fix issue #449 GoTest resets makeprog
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-x committed Jun 4, 2024
1 parent 588ab7b commit 2506882
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 57 deletions.
88 changes: 37 additions & 51 deletions lua/go/asyncmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,53 +146,7 @@ function M.make(...)
end
end

local bench = false
if makeprg:find('go test') then
-- log('go test')
-- runner = 'go test'
-- efm = compile_efm()
-- if optarg['c'] then
-- log('compile test')
-- compile_test = true
-- end
-- for _, arg in ipairs(args) do
-- --check if it is bench test
-- if arg:find('-bench') then
-- bench = true
-- end
-- end

-- if optarg['v'] then
-- table.insert(cmd, '-v')
-- end

-- if optarg['C'] then
-- table.insert(cmd, '-coverprofile=' .. optarg['C'])
-- end
-- if optarg['f'] then
-- log('fuzz test')
-- table.insert(cmd, '-fuzz')
-- end
-- if optarg['n'] then
-- table.insert(cmd, '-count=' .. optarg['n'])
-- end
-- if not bench and compile_test then
-- table.insert(cmd, '-c')
-- end
-- if optarg['r'] then
-- log('run test', optarg['r'])
-- table.insert(cmd, '-run')
-- table.insert(cmd, optarg['r'])
-- end
-- if optarg['b'] then
-- log('build test flags', optarg['b'])
-- table.insert(cmd, optarg['b'])
-- end
end

if bench then
cmd = vim.list_extend(cmd, args)
elseif args and #args > 0 then
if args and #args > 0 then
cmd = vim.list_extend(cmd, reminder)
end

Expand Down Expand Up @@ -262,7 +216,6 @@ M.runjob = function(cmd, runner, args, efm)
end

local function on_event(job_id, data, event)
-- log("stdout", data, event)
if event == 'stdout' then
if data then
for _, value in ipairs(data) do
Expand Down Expand Up @@ -332,8 +285,37 @@ M.runjob = function(cmd, runner, args, efm)
_GO_NVIM_CFG.on_stderr(event, data)
end

if cmdstr:find('go run') then
-- lets have some realtime feedbacks
local line_read = {}
if #lines > 0 then
line_read = vim.list_extend(line_read, lines)
end
if #errorlines > 0 then
line_read = vim.list_extend(line_read, errorlines)
end
-- normally the quickfix is 10lines in height
-- so we should truncate the output to 10 lines
if #line_read > 10 then
line_read = vim.list_slice(line_read, 1, 10)
end

log(line_read)
if #line_read > 0 then
vim.fn.setqflist({}, ' ', {
title = cmdstr,
lines = line_read,
})
-- if quickfix is not open, open it
util.quickfix('botright copen')
end

end
if event == 'exit' then
log(cmdstr .. 'exit with code: ', tostring(vim.v.shell_error))
local info = cmdstr .. ' exit with code: ' .. tostring(vim.v.shell_error)
vim.notify(info)
log(info)

sprite.on_close()
local info = cmdstr
local level = vim.log.levels.INFO
Expand Down Expand Up @@ -407,12 +389,16 @@ M.runjob = function(cmd, runner, args, efm)
if is_windows then -- gitshell & cmd.exe prefer list
runcmd = cmd
end
local buffered = true
if cmdstr:find('go run') then
buffered = false
end
_GO_NVIM_CFG.job_id = vim.fn.jobstart(runcmd, {
on_stderr = on_event,
on_stdout = on_event,
on_exit = on_event,
stdout_buffered = true,
stderr_buffered = true,
stdout_buffered = buffered,
stderr_buffered = buffered,
})
_GO_NVIM_CFG.on_jobstart(runcmd)
return cmd
Expand Down
6 changes: 0 additions & 6 deletions lua/go/gotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ local function run_test(path, args)
return cmd
end

vim.cmd([[setl makeprg=]] .. _GO_NVIM_CFG.go .. [[\ test]])

utils.log('test cmd', cmd)
local asyncmake = require('go.asyncmake')
return asyncmake.runjob(cmd, 'go test', args)
Expand Down Expand Up @@ -485,7 +483,6 @@ local function run_tests_with_ts_node(args, func_node, tblcase_ns)
return
end

vim.cmd([[setl makeprg=]] .. test_runner .. [[\ test]])
-- set_efm()
utils.log('test cmd', cmd)

Expand Down Expand Up @@ -651,10 +648,7 @@ M.test_file = function(...)
log(cmd_args)
return cmd_args
end

vim.cmd([[setl makeprg=]] .. _GO_NVIM_CFG.go .. [[\ test]])
log(cmd_args)

local cmdret = require('go.asyncmake').runjob(cmd_args, 'go test', args)

utils.log('test cmd: ', cmdret, ' finished')
Expand Down
9 changes: 9 additions & 0 deletions lua/go/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,15 @@ function util.quickfix(cmd)
vim.notify('trouble not found')
end
else
if cmd:find('copen') then
-- check if quickfix already opened
local total = vim.fn.winnr('$')
for i = 1, vim.fn.winnr('$') do
if vim.fn.getwinvar(i, '&buftype') == 'quickfix' then
return
end
end
end
vim.cmd(cmd)
end
end
Expand Down

0 comments on commit 2506882

Please sign in to comment.