fix TSamFailedOnly and the output formatting for the go-runner

This commit is contained in:
2025-12-25 17:27:30 +01:00
parent 1e2e881acd
commit 2c2cb35953
6 changed files with 443 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ local state = {
last_win = nil,
last_buf = nil,
last_command = nil,
last_runner = nil,
last_scope_command = nil,
last_scope_runner = nil,
last_scope_kind = nil,
@@ -57,6 +58,7 @@ function M.setup()
load_runners()
ensure_output_autocmds()
state.last_command = nil
state.last_runner = nil
state.last_scope_command = nil
state.last_scope_runner = nil
state.last_scope_kind = nil
@@ -337,6 +339,7 @@ local function run_command(command, opts)
cmd = vim.deepcopy(command.cmd),
cwd = command.cwd,
}
state.last_runner = options.runner
end
if options.track_scope then
state.last_scope_command = {
@@ -489,7 +492,18 @@ function M.run_last()
cmd = vim.deepcopy(state.last_command.cmd),
cwd = state.last_command.cwd,
}
run_command(command)
local runner = state.last_runner
local parser = nil
if runner then
parser = runner.output_parser
if type(parser) == "function" then
parser = parser()
end
end
run_command(command, {
runner = runner,
output_parser = parser or (runner and runner.parse_results),
})
end
function M.run_nearest()
@@ -642,7 +656,18 @@ function M.run_failed_only()
return
end
run_command(command, { save_last = false })
local runner = state.last_scope_runner
local parser = nil
if runner then
parser = runner.output_parser
if type(parser) == "function" then
parser = parser()
end
end
run_command(command, {
save_last = false,
output_parser = parser or (runner and runner.parse_results),
})
end
function M.show_output()

View File

@@ -201,6 +201,22 @@ function runner.build_file_command(bufnr)
local spec = { file = path, cwd = root }
local pkg = build_pkg_arg(spec)
local cmd = { "go", "test", "-json", pkg }
local lines = util.get_buf_lines(bufnr)
local funcs = find_test_functions(lines)
local names = {}
for _, fn in ipairs(funcs) do
table.insert(names, fn.name)
end
names = collect_unique(names)
if #names > 0 then
local pattern_parts = {}
for _, name in ipairs(names) do
table.insert(pattern_parts, escape_go_regex(name))
end
local pattern = "^(" .. table.concat(pattern_parts, "|") .. ")$"
table.insert(cmd, "-run")
table.insert(cmd, pattern)
end
return {
cmd = cmd,
cwd = root,