diff --git a/lua/tiny-debugger/breakpoints.lua b/lua/tiny-debugger/breakpoints.lua new file mode 100644 index 0000000..5edd89a --- /dev/null +++ b/lua/tiny-debugger/breakpoints.lua @@ -0,0 +1,29 @@ +local config = require("tiny-debugger.config") + +local M = {} + +local initialized = false + +function M.setup() + if initialized then return end + initialized = true + + require("persistent-breakpoints").setup({ + load_breakpoints_event = { "BufReadPost" }, + }) + + -- global mappings — these work outside debug mode + local keys = config.opts.keys + if keys.breakpoint then + vim.keymap.set("n", keys.breakpoint, function() + require("persistent-breakpoints.api").toggle_breakpoint() + end, { silent = true, desc = "tiny-debugger: toggle breakpoint" }) + end + if keys.cond_breakpoint then + vim.keymap.set("n", keys.cond_breakpoint, function() + require("persistent-breakpoints.api").set_conditional_breakpoint() + end, { silent = true, desc = "tiny-debugger: conditional breakpoint" }) + end +end + +return M diff --git a/lua/tiny-debugger/init.lua b/lua/tiny-debugger/init.lua index 8b52744..120c02f 100644 --- a/lua/tiny-debugger/init.lua +++ b/lua/tiny-debugger/init.lua @@ -1,10 +1,12 @@ local config = require("tiny-debugger.config") local mode = require("tiny-debugger.mode") +local breakpoints = require("tiny-debugger.breakpoints") local M = {} function M.setup(opts) config.merge(opts) + breakpoints.setup() end function M.toggle() diff --git a/plugin/tiny-debugger.lua b/plugin/tiny-debugger.lua index 57f312d..d3effda 100644 --- a/plugin/tiny-debugger.lua +++ b/plugin/tiny-debugger.lua @@ -13,6 +13,9 @@ vim.pack.add({ "nvim-neotest/nvim-nio" }) vim.pack.add({ "theHamsta/nvim-dap-virtual-text" }) vim.pack.add({ "Weissle/persistent-breakpoints.nvim" }) +-- initialize with defaults (user can call setup() to override) +require("tiny-debugger").setup() + -- toggle debug mode vim.keymap.set("n", "d", function() require("tiny-debugger").toggle() diff --git a/tests/test_breakpoints.lua b/tests/test_breakpoints.lua new file mode 100644 index 0000000..0829bc5 --- /dev/null +++ b/tests/test_breakpoints.lua @@ -0,0 +1,24 @@ +-- tests for persistent breakpoints +local td = require("tiny-debugger") +td.setup() + +local function assert_eq(a, b, msg) + if a ~= b then + error(string.format("FAIL: %s — expected %s, got %s", msg, vim.inspect(b), vim.inspect(a))) + end +end + +-- test 1: global x mapping exists +local maparg = vim.fn.maparg("x", "n", false, true) +assert_eq(maparg.desc, "tiny-debugger: toggle breakpoint", "global x mapping exists") + +-- test 2: global X mapping exists +maparg = vim.fn.maparg("X", "n", false, true) +assert_eq(maparg.desc, "tiny-debugger: conditional breakpoint", "global X mapping exists") + +-- test 3: persistent-breakpoints API is callable +local api = require("persistent-breakpoints.api") +assert_eq(type(api.toggle_breakpoint), "function", "toggle_breakpoint is a function") +assert_eq(type(api.set_conditional_breakpoint), "function", "set_conditional_breakpoint is a function") + +print("ALL BREAKPOINT TESTS PASSED")