Skip to content

Commit 479cb6e

Browse files
committed
feat: Enhances breakpoint editing
The keymapping `<leader>B` is now configured to guide users through the process of adding a `condition`, `hitCondition`, and `logMessage` to a breakpoint.
1 parent 6ba2408 commit 479cb6e

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

lua/kickstart/plugins/debug.lua

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,58 @@ return {
6464
{
6565
'<leader>B',
6666
function()
67-
require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ')
67+
local dap = require 'dap'
68+
-- Search for an existing breakpoing on this line in this buffer
69+
---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder
70+
local function find_bp()
71+
local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()]
72+
---@type dap.SourceBreakpoint
73+
local bp = { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' }
74+
for _, candidate in ipairs(buf_bps) do
75+
if candidate.line and candidate.line == vim.fn.line '.' then
76+
bp = candidate
77+
break
78+
end
79+
end
80+
return bp
81+
end
82+
83+
-- Elicit customization via a UI prompt
84+
---@param bp dap.SourceBreakpoint a breakpoint
85+
local function customize_bp(bp)
86+
local fields = {
87+
('Condition: (%s)\n'):format(bp.condition),
88+
('Hit Condition: (%s)\n'):format(bp.hitCondition),
89+
('Log Message: (%s)\n'):format(bp.logMessage),
90+
}
91+
vim.ui.select(fields, {
92+
prompt = 'Edit breakpoint',
93+
}, function(choice)
94+
if choice == fields[1] then
95+
bp.condition = vim.fn.input {
96+
prompt = 'Condition: ',
97+
default = bp.condition,
98+
}
99+
elseif choice == fields[2] then
100+
bp.hitCondition = vim.fn.input {
101+
prompt = 'Hit Condition: ',
102+
default = bp.hitCondition,
103+
}
104+
elseif choice == fields[3] then
105+
bp.logMessage = vim.fn.input {
106+
prompt = 'Log Message: ',
107+
default = bp.logMessage,
108+
}
109+
end
110+
111+
-- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
112+
dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage)
113+
end)
114+
end
115+
116+
customize_bp(find_bp())
68117
end,
69-
desc = 'Debug: Set Breakpoint',
118+
desc = 'Debug: Edit Breakpoint',
70119
},
71120
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
72121
{

0 commit comments

Comments
 (0)