add TSamLast command for reexecuting last running tests

This commit is contained in:
2025-12-25 14:30:34 +01:00
parent 51ec535eac
commit cbc3e201ae
8 changed files with 260 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ local state = {
runners = {},
last_win = nil,
last_buf = nil,
last_command = nil,
autocmds_set = false,
}
@@ -50,6 +51,7 @@ end
function M.setup()
load_runners()
ensure_output_autocmds()
state.last_command = nil
end
function M.reload_runners()
@@ -298,6 +300,12 @@ local function run_cmd(cmd, cwd, handlers)
end
local function run_command(command)
if command and type(command.cmd) == "table" and #command.cmd > 0 then
state.last_command = {
cmd = vim.deepcopy(command.cmd),
cwd = command.cwd,
}
end
local cmd = command.cmd
local cwd = command.cwd or vim.loop.cwd()
@@ -350,6 +358,19 @@ local function run_command(command)
})
end
function M.run_last()
if not (state.last_command and type(state.last_command.cmd) == "table") then
vim.notify("[test-samurai] No previous test command", vim.log.levels.WARN)
return
end
local command = {
cmd = vim.deepcopy(state.last_command.cmd),
cwd = state.last_command.cwd,
}
run_command(command)
end
function M.run_nearest()
local bufnr = vim.api.nvim_get_current_buf()
local pos = vim.api.nvim_win_get_cursor(0)