Skip to content

Commit

Permalink
feat(summary): mappings help window
Browse files Browse the repository at this point in the history

Co-authored-by: Rónán Carrigan <[email protected]>
  • Loading branch information
Grafcube and rcarriga authored Mar 18, 2024
1 parent 4440cc2 commit 56b720a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/neotest/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ local default_config = {
next_failed = "J",
prev_failed = "K",
watch = "w",
help = "?",
},
},
benchmark = {
Expand Down
32 changes: 32 additions & 0 deletions lua/neotest/consumers/summary/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,38 @@ function SummaryComponent:_render(canvas, tree, expanded, focused, indent)
neotest.summary.clear_marked({ adapter = self.adapter_id })
end)

canvas:add_mapping(
"help",
async_func(function()
local help_text = {}
local width = 0
for name, mapping in pairs(config.summary.mappings) do
local mappings = type(mapping) == "table" and table.concat(mapping, ", ") or mapping
local line = "(" .. name .. "): " .. mappings
width = math.max(width, #line)
table.insert(help_text, line)
end

table.insert(help_text, 1, "Mappings")
width = math.max(width, #help_text[1])
table.insert(help_text, 2, string.rep("=", width))

local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, help_text)
vim.api.nvim_buf_set_option(buf, "modifiable", false)
local float = lib.ui.float.open({
width = width,
height = #help_text,
buffer = buf,
auto_close = true,
})
local win = float.win_id
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_set_current_win(win)
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>q<CR>", { noremap = true, silent = true })
end)
)

local status = self:_get_status(position)
has_running = has_running or status == "running"

Expand Down

0 comments on commit 56b720a

Please sign in to comment.