expand opening keymap on detail-float
All checks were successful
tests / test (push) Successful in 8s

This commit is contained in:
2026-01-23 10:42:25 +01:00
parent 456a157549
commit 5d205c0302
4 changed files with 176 additions and 40 deletions

View File

@@ -67,7 +67,7 @@ Additional keymaps:
- `<leader>fn` -> [F]ind [N]ext failed test in listing (wraps to the first, opens Detail-Float, works in Detail-Float) - `<leader>fn` -> [F]ind [N]ext failed test in listing (wraps to the first, opens Detail-Float, works in Detail-Float)
- `<leader>fp` -> [F]ind [P]revious failed test in listing (wraps to the last, opens Detail-Float, works in Detail-Float) - `<leader>fp` -> [F]ind [P]revious failed test in listing (wraps to the last, opens Detail-Float, works in Detail-Float)
- `<leader>ff` -> [F]ind [F]irst list entry (opens Detail-Float, works in Detail-Float) - `<leader>ff` -> [F]ind [F]irst list entry (opens Detail-Float, works in Detail-Float)
- `<leader>o` -> jump to the test location - `<leader>o` -> jump to the test location (works in Detail-Float)
- `<leader>qn` -> close the testing floats and jump to the first quickfix entry - `<leader>qn` -> close the testing floats and jump to the first quickfix entry
- Listing filters: - Listing filters:
- `<leader>sf` -> filter the listing to `[ FAIL ] - ...` entries - `<leader>sf` -> filter the listing to `[ FAIL ] - ...` entries

View File

@@ -55,7 +55,7 @@ Listing navigation:
<leader>fn [F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float) <leader>fn [F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float)
<leader>fp [F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float) <leader>fp [F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float)
<leader>ff [F]ind [F]irst list entry (opens Detail-Float; works in Detail-Float) <leader>ff [F]ind [F]irst list entry (opens Detail-Float; works in Detail-Float)
<leader>o Jump to test location <leader>o Jump to test location (works in Detail-Float)
<leader>qn Close floats + jump to the first quickfix entry <leader>qn Close floats + jump to the first quickfix entry
Listing filters: Listing filters:
<leader>sf Filter listing to [ FAIL ] only <leader>sf Filter listing to [ FAIL ] only

View File

@@ -70,7 +70,7 @@ local function help_lines()
" <leader>fn [F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float)", " <leader>fn [F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float)",
" <leader>fp [F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float)", " <leader>fp [F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float)",
" <leader>ff [F]ind [F]irst list entry (opens Detail-Float; works in Detail-Float)", " <leader>ff [F]ind [F]irst list entry (opens Detail-Float; works in Detail-Float)",
" <leader>o Jump to test location", " <leader>o Jump to test location (works in Detail-Float)",
" <leader>qn Close floats + jump to first quickfix entry", " <leader>qn Close floats + jump to first quickfix entry",
"", "",
"Listing filters:", "Listing filters:",
@@ -469,9 +469,27 @@ local function restore_trigger_location()
end end
local function jump_to_listing_test() local function jump_to_listing_test()
local cursor = vim.api.nvim_win_get_cursor(0) local line = nil
local line = cursor[1] local text = nil
local text = vim.api.nvim_get_current_line() local buf = vim.api.nvim_get_current_buf()
if state.detail_buf and buf == state.detail_buf then
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
return
end
line = state.detail_line
if not line then
return
end
local lines = vim.api.nvim_buf_get_lines(state.last_buf, line - 1, line, false)
text = lines and lines[1] or nil
else
local cursor = vim.api.nvim_win_get_cursor(0)
line = cursor[1]
text = vim.api.nvim_get_current_line()
end
if not line or not text then
return
end
local status = text:match("^%[%s*(%u+)%s*%]%s*%-") local status = text:match("^%[%s*(%u+)%s*%]%s*%-")
if status ~= "PASS" and status ~= "FAIL" and status ~= "SKIP" then if status ~= "PASS" and status ~= "FAIL" and status ~= "SKIP" then
return return
@@ -1340,6 +1358,46 @@ local function parse_go_output_from_raw(output)
return out return out
end end
local function set_detail_maps(buf)
vim.keymap.set("n", "<esc><esc>", function()
close_container_and_restore()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<C-w>h", function()
M.focus_listing()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<C-h>", function()
M.focus_listing()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<C-l>", function()
M.focus_detail()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>z", function()
M.toggle_detail_full()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>fn", function()
jump_listing_and_open("next")
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>fp", function()
jump_listing_and_open("prev")
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>ff", function()
jump_listing_and_open("first")
end, { buffer = buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
vim.keymap.set("n", "<C-c>", function()
close_detail_float()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>qn", function()
jump_to_first_quickfix()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>o", function()
jump_to_listing_test()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "?", function()
M.show_help()
end, { buffer = buf, nowait = true, silent = true })
disable_container_maps(buf)
end
local function ensure_detail_buf(lines) local function ensure_detail_buf(lines)
local buf = state.detail_buf local buf = state.detail_buf
if not (buf and vim.api.nvim_buf_is_valid(buf)) then if not (buf and vim.api.nvim_buf_is_valid(buf)) then
@@ -1349,41 +1407,8 @@ local function ensure_detail_buf(lines)
vim.api.nvim_buf_set_option(buf, "swapfile", false) vim.api.nvim_buf_set_option(buf, "swapfile", false)
vim.api.nvim_buf_set_option(buf, "filetype", "test-samurai-output") vim.api.nvim_buf_set_option(buf, "filetype", "test-samurai-output")
state.detail_buf = buf state.detail_buf = buf
vim.keymap.set("n", "<esc><esc>", function()
close_container_and_restore()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<C-w>h", function()
M.focus_listing()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<C-h>", function()
M.focus_listing()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<C-l>", function()
M.focus_detail()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>z", function()
M.toggle_detail_full()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>fn", function()
jump_listing_and_open("next")
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>fp", function()
jump_listing_and_open("prev")
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>ff", function()
jump_listing_and_open("first")
end, { buffer = buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
vim.keymap.set("n", "<C-c>", function()
close_detail_float()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>qn", function()
jump_to_first_quickfix()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "?", function()
M.show_help()
end, { buffer = buf, nowait = true, silent = true })
disable_container_maps(buf)
end end
set_detail_maps(buf)
local clean_lines, highlights = parse_ansi_lines(normalize_output_lines(lines)) local clean_lines, highlights = parse_ansi_lines(normalize_output_lines(lines))
vim.api.nvim_buf_set_lines(buf, 0, -1, false, clean_lines) vim.api.nvim_buf_set_lines(buf, 0, -1, false, clean_lines)
vim.api.nvim_buf_clear_namespace(buf, help_ns, 0, -1) vim.api.nvim_buf_clear_namespace(buf, help_ns, 0, -1)

View File

@@ -1358,4 +1358,115 @@ describe("test-samurai core (no bundled runners)", function()
local detail_lines = vim.api.nvim_buf_get_lines(refreshed_buf, 0, -1, false) local detail_lines = vim.api.nvim_buf_get_lines(refreshed_buf, 0, -1, false)
assert.same({ "", "No output captured" }, detail_lines) assert.same({ "", "No output captured" }, detail_lines)
end) end)
it("allows <leader>o from the detail float to jump to the test location", function()
local runner = {
name = "test-runner-detail-o",
}
function runner.is_test_file(_bufnr)
return true
end
function runner.find_nearest(bufnr, _row, _col)
return { file = vim.api.nvim_buf_get_name(bufnr), cwd = vim.loop.cwd(), test_name = "TestJump" }
end
function runner.build_command(spec)
return { cmd = { "echo", "nearest" }, cwd = spec.cwd }
end
function runner.build_file_command(_bufnr)
return { cmd = { "echo", "file" } }
end
function runner.build_all_command(_bufnr)
return { cmd = { "echo", "all" } }
end
function runner.build_failed_command(last_command, _failures, _scope_kind)
return { cmd = { "echo", "failed" }, cwd = last_command and last_command.cwd or nil }
end
function runner.parse_results(_output)
return { passes = {}, failures = { "TestJump" }, skips = {} }
end
function runner.output_parser()
return {
on_complete = function(output, _state)
return runner.parse_results(output)
end,
}
end
function runner.parse_test_output(_output)
return {}
end
function runner.collect_failed_locations(_failures, _command, _scope_kind)
return { { filename = "/tmp/test_jump_detail.go", lnum = 2, col = 3 } }
end
package.loaded["test-samurai-detail-o-runner"] = runner
test_samurai.setup({ runner_modules = { "test-samurai-detail-o-runner" } })
local target_buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(target_buf, "/tmp/test_jump_detail.go")
vim.api.nvim_buf_set_lines(target_buf, 0, -1, false, { "line1", "line2", "line3" })
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_runner_detail_o.go")
vim.bo[bufnr].filetype = "go"
vim.api.nvim_set_current_buf(bufnr)
local orig_jobstart = vim.fn.jobstart
vim.fn.jobstart = function(_cmd, opts)
if opts.on_exit then
opts.on_exit(nil, 0, nil)
end
return 1
end
core.run_nearest()
vim.fn.jobstart = orig_jobstart
local listing_buf = vim.api.nvim_get_current_buf()
assert.is_true(vim.bo[listing_buf].filetype == "test-samurai-output")
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
local fail_entry = nil
for i, line in ipairs(lines) do
if line:match("^%[ FAIL %] %- ") then
fail_entry = i
break
end
end
assert.is_true(fail_entry ~= nil)
vim.api.nvim_win_set_cursor(0, { fail_entry, 0 })
core.open_test_output_at_cursor()
local detail_buf = vim.api.nvim_get_current_buf()
local maps = vim.api.nvim_buf_get_keymap(detail_buf, "n")
local found = nil
for _, map in ipairs(maps) do
if type(map.lhs) == "string" and map.lhs:sub(-1) == "o" then
found = map
break
end
end
assert.is_true(found ~= nil)
assert.is_true(type(found.callback) == "function")
found.callback()
local current = vim.api.nvim_get_current_buf()
local name = vim.api.nvim_buf_get_name(current)
assert.is_true(name:sub(-#"/tmp/test_jump_detail.go") == "/tmp/test_jump_detail.go")
local cursor = vim.api.nvim_win_get_cursor(0)
assert.equals(2, cursor[1])
assert.equals(2, cursor[2])
end)
end) end)