Skip to content

Commit dad972e

Browse files
blehreroriori1703
authored andcommitted
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 7cc245e commit dad972e

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

lua/kickstart/plugins/debug.lua

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,62 @@ return {
3333
{ '<F2>', function() require('dap').step_over() end, desc = 'Debug: Step Over' },
3434
{ '<F3>', function() require('dap').step_out() end, desc = 'Debug: Step Out' },
3535
{ '<leader>b', function() require('dap').toggle_breakpoint() end, desc = 'Debug: Toggle Breakpoint' },
36-
{ '<leader>B', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, desc = 'Debug: Set Breakpoint' },
36+
{
37+
'<leader>B',
38+
function()
39+
local dap = require 'dap'
40+
-- Search for an existing breakpoing on this line in this buffer
41+
---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder
42+
local function find_bp()
43+
local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()]
44+
---@type dap.SourceBreakpoint
45+
local bp = { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' }
46+
for _, candidate in ipairs(buf_bps) do
47+
if candidate.line and candidate.line == vim.fn.line '.' then
48+
bp = candidate
49+
break
50+
end
51+
end
52+
return bp
53+
end
54+
55+
-- Elicit customization via a UI prompt
56+
---@param bp dap.SourceBreakpoint a breakpoint
57+
local function customize_bp(bp)
58+
local fields = {
59+
('Condition: (%s)\n'):format(bp.condition),
60+
('Hit Condition: (%s)\n'):format(bp.hitCondition),
61+
('Log Message: (%s)\n'):format(bp.logMessage),
62+
}
63+
vim.ui.select(fields, {
64+
prompt = 'Edit breakpoint',
65+
}, function(choice)
66+
if choice == fields[1] then
67+
bp.condition = vim.fn.input {
68+
prompt = 'Condition: ',
69+
default = bp.condition,
70+
}
71+
elseif choice == fields[2] then
72+
bp.hitCondition = vim.fn.input {
73+
prompt = 'Hit Condition: ',
74+
default = bp.hitCondition,
75+
}
76+
elseif choice == fields[3] then
77+
bp.logMessage = vim.fn.input {
78+
prompt = 'Log Message: ',
79+
default = bp.logMessage,
80+
}
81+
end
82+
83+
-- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
84+
dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage)
85+
end)
86+
end
87+
88+
customize_bp(find_bp())
89+
end,
90+
desc = 'Debug: Edit Breakpoint',
91+
},
3792
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
3893
{ '<F7>', function() require('dapui').toggle() end, desc = 'Debug: See last session result.' },
3994
},

0 commit comments

Comments
 (0)