add new keypmap for quick selecting first entry

This commit is contained in:
2026-01-17 15:44:47 +01:00
parent 24bd89a7be
commit bd6930adc0
4 changed files with 294 additions and 24 deletions

View File

@@ -36,6 +36,7 @@ local state = {
local summary_ns = vim.api.nvim_create_namespace("TestSamuraiSummary")
local result_ns = vim.api.nvim_create_namespace("TestSamuraiResult")
local detail_ns = vim.api.nvim_create_namespace("TestSamuraiDetailAnsi")
local help_ns = vim.api.nvim_create_namespace("TestSamuraiHelp")
local apply_border_kind
local close_container
local restore_listing_full
@@ -55,7 +56,7 @@ local function help_lines()
return {
"Test-Samurai Help",
"",
"TSam Commands:",
"TSam commands:",
" TSamNearest <leader>tn",
" TSamFile <leader>tf",
" TSamAll <leader>ta",
@@ -63,14 +64,22 @@ local function help_lines()
" TSamFailedOnly <leader>te",
" TSamShowOutput <leader>to",
"",
"Standard Keymaps:",
"Listing navigation:",
" <leader>fn [F]ind [N]ext failed test in listing",
" <leader>fp [F]ind [P]revious failed test in listing",
" <leader>ff [F]ind [F]irst list entry",
" <leader>o Jump to test location",
" <leader>qn Close floats + jump to first quickfix entry",
" <leader>nf Next [ FAIL ] in listing",
" <leader>pf Previous [ FAIL ] in listing",
"",
"Listing filters:",
" <leader>sf Filter listing to [ FAIL ] only",
" <leader>ss Filter listing to [ SKIP ] only",
" <leader>sa Show all listing entries (clear filter)",
"",
"Listing actions:",
" <leader>tt Run the test under the cursor",
" <leader>cb breaks test-command onto multiple lines (clears search highlight)",
" <leader>cj joins test-command onto single line",
"",
"Testing-Float (Listing):",
" <cr> Open Detail-Float for selected test",
@@ -78,9 +87,6 @@ local function help_lines()
" <C-l> Focus Detail-Float (press l again for full)",
" <C-h> Focus Test-Listing-Float",
" <leader>z Toggle Detail-Float full width",
" <leader>o Jump to test location",
" <leader>cb breaks test-command onto multiple lines (clears search highlight)",
" <leader>cj joins test-command onto single line",
" ? Show this help",
"",
"Testing-Float (Detail):",
@@ -330,6 +336,25 @@ local function jump_listing_fail(direction)
end
end
local function jump_to_first_listing_entry()
local win = vim.api.nvim_get_current_win()
local buf = vim.api.nvim_get_current_buf()
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
return
end
local total = vim.api.nvim_buf_line_count(buf)
if total == 0 then
return
end
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
for i = 1, total do
if lines[i] and lines[i]:match("^%[ %u+ %] %- ") then
vim.api.nvim_win_set_cursor(win, { i, 0 })
return
end
end
end
local function find_normal_window()
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
local cfg = vim.api.nvim_win_get_config(win)
@@ -833,12 +858,15 @@ local function create_output_win(initial_lines)
vim.keymap.set("n", "<leader>z", function()
M.toggle_detail_full()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>nf", function()
vim.keymap.set("n", "<leader>fn", function()
jump_listing_fail("next")
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>pf", function()
vim.keymap.set("n", "<leader>fp", function()
jump_listing_fail("prev")
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>ff", function()
jump_to_first_listing_entry()
end, { buffer = buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
vim.keymap.set("n", "<leader>cb", function()
M.listing_break_on_dashes()
end, { buffer = buf, nowait = true, silent = true })
@@ -919,12 +947,15 @@ local function reopen_output_win()
vim.keymap.set("n", "<leader>z", function()
M.toggle_detail_full()
end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>nf", function()
vim.keymap.set("n", "<leader>fn", function()
jump_listing_fail("next")
end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>pf", function()
vim.keymap.set("n", "<leader>fp", function()
jump_listing_fail("prev")
end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>ff", function()
jump_to_first_listing_entry()
end, { buffer = state.last_buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
vim.keymap.set("n", "<leader>cb", function()
M.listing_break_on_dashes()
end, { buffer = state.last_buf, nowait = true, silent = true })
@@ -1214,6 +1245,18 @@ local function apply_detail_highlights(buf, highlights)
end
end
local function apply_help_highlights(buf, lines)
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
return
end
vim.api.nvim_buf_clear_namespace(buf, help_ns, 0, -1)
for lnum, line in ipairs(lines or {}) do
if line:match(":%s*$") then
vim.api.nvim_buf_add_highlight(buf, help_ns, "TestSamuraiSummaryPass", lnum - 1, 0, -1)
end
end
end
local function parse_go_output_from_raw(output)
local out = {}
if not output or output == "" then
@@ -1274,6 +1317,7 @@ local function ensure_detail_buf(lines)
end
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_clear_namespace(buf, help_ns, 0, -1)
apply_detail_highlights(buf, highlights)
return buf
end
@@ -1403,7 +1447,9 @@ function M.show_help()
vim.notify("[test-samurai] No test output window", vim.log.levels.WARN)
return
end
open_detail_split(help_lines(), "default")
local lines = help_lines()
open_detail_split(lines, "default")
apply_help_highlights(state.detail_buf, lines)
end
function M.filter_listing_failures()