@@ -33,7 +33,76 @@ 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+ require ' dap.protocol'
40+ local dap = require ' dap'
41+ -- Search for an existing breakpoint on this line in this buffer
42+ --- @return dap.SourceBreakpoint bp that was either found , or an empty placeholder
43+ local function find_bp ()
44+ local buf_bps = require (' dap.breakpoints' ).get (vim .fn .bufnr ())[vim .fn .bufnr ()]
45+ --- @type dap.SourceBreakpoint
46+ for _ , candidate in ipairs (buf_bps ) do
47+ if candidate .line and candidate .line == vim .fn .line ' .' then
48+ return candidate
49+ end
50+ end
51+ return { condition = ' ' , logMessage = ' ' , hitCondition = ' ' , line = vim .fn .line ' .' }
52+ end
53+
54+ -- Elicit customization via a UI prompt
55+ --- @param bp dap.SourceBreakpoint a breakpoint
56+ local function customize_bp (bp )
57+ local props = {
58+ [' Condition' ] = {
59+ value = bp .condition ,
60+ setter = function (v )
61+ bp .condition = v
62+ end ,
63+ },
64+ [' Hit Condition' ] = {
65+ value = bp .hitCondition ,
66+ setter = function (v )
67+ bp .hitCondition = v
68+ end ,
69+ },
70+ [' Log Message' ] = {
71+ value = bp .logMessage ,
72+ setter = function (v )
73+ bp .logMessage = v
74+ end ,
75+ },
76+ }
77+ local menu_options = {}
78+ for k , _ in pairs (props ) do
79+ table.insert (menu_options , k )
80+ end
81+ vim .ui .select (menu_options , {
82+ prompt = ' Edit Breakpoint' ,
83+ format_item = function (item )
84+ return (' %s: %s' ):format (item , props [item ].value )
85+ end ,
86+ }, function (choice )
87+ if choice == nil then
88+ -- User cancelled the selection
89+ return
90+ end
91+
92+ props [choice ].setter (vim .fn .input {
93+ prompt = (' [%s] ' ):format (choice ),
94+ default = props [choice ].value ,
95+ })
96+
97+ -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
98+ dap .set_breakpoint (bp .condition , bp .hitCondition , bp .logMessage )
99+ end )
100+ end
101+
102+ customize_bp (find_bp ())
103+ end ,
104+ desc = ' Debug: Edit Breakpoint' ,
105+ },
37106 -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
38107 { ' <F7>' , function () require (' dapui' ).toggle () end , desc = ' Debug: See last session result.' },
39108 },
0 commit comments