feat: move all debug keys under <leader>d prefix with which-key support

This commit is contained in:
swaits committed 2026-04-11 19:16:36 -06:00
1 parent 94eef8eaca
commit bc015cd8dc
9 files changed
+119 -72

No files matched your search

+5 -5
View File
@@ -27,16 +27,16 @@ function M.setup()
vim.fn.sign_define("DapLogPoint", { text = "📝", texthl = "DapLogPoint" })
-- global mappings (work outside debug mode)
local keys = config.opts.keys
local gk = config.opts.global_keys
local pb = require("persistent-breakpoints.api")
local bindings = {
{ keys.breakpoint, pb.toggle_breakpoint, "toggle breakpoint" },
{ keys.cond_breakpoint, pb.set_conditional_breakpoint, "conditional breakpoint" },
{ keys.clear_breakpoints, pb.clear_all_breakpoints, "clear all breakpoints" },
{ gk.breakpoint, pb.toggle_breakpoint, "Toggle breakpoint" },
{ gk.cond_breakpoint, pb.set_conditional_breakpoint, "Conditional breakpoint" },
{ gk.clear_breakpoints, pb.clear_all_breakpoints, "Clear all breakpoints" },
}
for _, b in ipairs(bindings) do
if b[1] then
vim.keymap.set("n", b[1], b[2], { silent = true, desc = "tiny-debugger: " .. b[3] })
vim.keymap.set("n", b[1], b[2], { silent = true, desc = b[3] })
end
end
end
+16 -6
View File
@@ -4,23 +4,29 @@ M.defaults = {
help_on_enter = true,
builtin_adapters = true,
-- modal keys (active only during debug mode, single-key)
keys = {
continue = "c",
step_over = "s",
step_into = "d",
step_out = "r",
run_to_cursor = "C",
breakpoint = "<leader>x",
cond_breakpoint = "<leader>X",
watch = "W",
hover = "K",
eval = "E",
terminate = "q",
restart = "R",
clear_breakpoints = "<leader>D",
help = "?",
},
-- global keys (always available, <leader>d prefix)
global_keys = {
toggle = "<leader>dd",
breakpoint = "<leader>dx",
cond_breakpoint = "<leader>dX",
clear_breakpoints = "<leader>dD",
},
dapui = {
controls = { enabled = false },
layouts = {
@@ -58,9 +64,13 @@ M.opts = M.defaults
function M.merge(user_opts)
M.opts = vim.tbl_deep_extend("force", vim.deepcopy(M.defaults), user_opts or {})
if user_opts and user_opts.keys then
for k, v in pairs(user_opts.keys) do
if v == false then M.opts.keys[k] = false end
if user_opts then
for _, tbl_name in ipairs({ "keys", "global_keys" }) do
if user_opts[tbl_name] then
for k, v in pairs(user_opts[tbl_name]) do
if v == false then M.opts[tbl_name][k] = false end
end
end
end
end
return M.opts
+28 -13
View File
@@ -5,15 +5,12 @@ local M = {}
local win_id = nil
local buf_id = nil
local key_info = {
local modal_info = {
{ "continue", "Continue" },
{ "step_over", "Step over" },
{ "step_into", "Step into" },
{ "step_out", "Step out" },
{ "run_to_cursor", "Run to cursor" },
{ "breakpoint", "Toggle breakpoint" },
{ "cond_breakpoint", "Conditional breakpoint" },
{ "clear_breakpoints", "Clear all breakpoints" },
{ "watch", "Watch expression" },
{ "hover", "Hover / inspect" },
{ "eval", "Eval in REPL" },
@@ -22,18 +19,36 @@ local key_info = {
{ "help", "Show this help" },
}
local global_info = {
{ "toggle", "Toggle debug mode" },
{ "breakpoint", "Toggle breakpoint" },
{ "cond_breakpoint", "Conditional breakpoint" },
{ "clear_breakpoints", "Clear all breakpoints" },
}
local function build_content()
local lines = { " tiny-debugger keybindings", "" }
local lines = { " tiny-debugger", "" }
local width = #lines[1]
local keys = config.opts.keys
for _, pair in ipairs(key_info) do
local key = keys[pair[1]]
if key then
local line = string.format(" %s %s", key, pair[2])
lines[#lines + 1] = line
if #line > width then width = #line end
end
local function add(key, label)
local line = string.format(" %-12s %s", key, label)
lines[#lines + 1] = line
if #line > width then width = #line end
end
lines[#lines + 1] = " Debug mode:"
for _, pair in ipairs(modal_info) do
local key = config.opts.keys[pair[1]]
if key then add(key, pair[2]) end
end
lines[#lines + 1] = ""
lines[#lines + 1] = " Always available:"
for _, pair in ipairs(global_info) do
local key = config.opts.global_keys[pair[1]]
if key then add(key, pair[2]) end
end
lines[#lines + 1] = ""
return lines, width + 2
end
+13
View File
@@ -3,10 +3,23 @@ local mode = require("tiny-debugger.mode")
local M = {}
local setup_done = false
function M.setup(opts)
if setup_done then return end
setup_done = true
config.merge(opts)
require("tiny-debugger.breakpoints").setup()
require("tiny-debugger.adapters").setup()
-- global toggle keybinding
local toggle_key = config.opts.global_keys.toggle
if toggle_key then
vim.keymap.set("n", toggle_key, function() mode.toggle() end, {
silent = true, desc = "Toggle debug mode",
})
end
end
function M.toggle()