@@ -33,7 +33,66 @@ 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 return candidate end
48+ end
49+ return { condition = ' ' , logMessage = ' ' , hitCondition = ' ' , line = vim .fn .line ' .' }
50+ end
51+
52+ -- Elicit customization via a UI prompt
53+ --- @param bp dap.SourceBreakpoint a breakpoint
54+ local function customize_bp (bp )
55+ local props = {
56+ [' Condition' ] = {
57+ value = bp .condition ,
58+ setter = function (v ) bp .condition = v end ,
59+ },
60+ [' Hit Condition' ] = {
61+ value = bp .hitCondition ,
62+ setter = function (v ) bp .hitCondition = v end ,
63+ },
64+ [' Log Message' ] = {
65+ value = bp .logMessage ,
66+ setter = function (v ) bp .logMessage = v end ,
67+ },
68+ }
69+ local menu_options = {}
70+ for k , _ in pairs (props ) do
71+ table.insert (menu_options , k )
72+ end
73+ vim .ui .select (menu_options , {
74+ prompt = ' Edit Breakpoint' ,
75+ format_item = function (item ) return (' %s: %s' ):format (item , props [item ].value ) end ,
76+ }, function (choice )
77+ if choice == nil then
78+ -- User cancelled the selection
79+ return
80+ end
81+
82+ props [choice ].setter (vim .fn .input {
83+ prompt = (' [%s] ' ):format (choice ),
84+ default = props [choice ].value ,
85+ })
86+
87+ -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
88+ dap .set_breakpoint (bp .condition , bp .hitCondition , bp .logMessage )
89+ end )
90+ end
91+
92+ customize_bp (find_bp ())
93+ end ,
94+ desc = ' Debug: Edit Breakpoint' ,
95+ },
3796 -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
3897 { ' <F7>' , function () require (' dapui' ).toggle () end , desc = ' Debug: See last session result.' },
3998 },
0 commit comments