From dad972eb9e3f9872af6aff2dc73298aeccaa3195 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Tue, 13 May 2025 01:46:02 -0700 Subject: [PATCH 01/11] feat: Enhances breakpoint editing The keymapping `B` is now configured to guide users through the process of adding a `condition`, `hitCondition`, and `logMessage` to a breakpoint. --- lua/kickstart/plugins/debug.lua | 57 ++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 7e58905e830..e38d2ff0765 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -33,7 +33,62 @@ return { { '', function() require('dap').step_over() end, desc = 'Debug: Step Over' }, { '', function() require('dap').step_out() end, desc = 'Debug: Step Out' }, { 'b', function() require('dap').toggle_breakpoint() end, desc = 'Debug: Toggle Breakpoint' }, - { 'B', function() require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') end, desc = 'Debug: Set Breakpoint' }, + { + 'B', + function() + local dap = require 'dap' + -- Search for an existing breakpoing on this line in this buffer + ---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder + local function find_bp() + local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()] + ---@type dap.SourceBreakpoint + local bp = { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' } + for _, candidate in ipairs(buf_bps) do + if candidate.line and candidate.line == vim.fn.line '.' then + bp = candidate + break + end + end + return bp + end + + -- Elicit customization via a UI prompt + ---@param bp dap.SourceBreakpoint a breakpoint + local function customize_bp(bp) + local fields = { + ('Condition: (%s)\n'):format(bp.condition), + ('Hit Condition: (%s)\n'):format(bp.hitCondition), + ('Log Message: (%s)\n'):format(bp.logMessage), + } + vim.ui.select(fields, { + prompt = 'Edit breakpoint', + }, function(choice) + if choice == fields[1] then + bp.condition = vim.fn.input { + prompt = 'Condition: ', + default = bp.condition, + } + elseif choice == fields[2] then + bp.hitCondition = vim.fn.input { + prompt = 'Hit Condition: ', + default = bp.hitCondition, + } + elseif choice == fields[3] then + bp.logMessage = vim.fn.input { + prompt = 'Log Message: ', + default = bp.logMessage, + } + end + + -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint()) + dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage) + end) + end + + customize_bp(find_bp()) + end, + desc = 'Debug: Edit Breakpoint', + }, -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. { '', function() require('dapui').toggle() end, desc = 'Debug: See last session result.' }, }, From 72bb5c82f383afc3256d7d911f1faa1643b6a9d9 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Tue, 13 May 2025 19:13:41 -0700 Subject: [PATCH 02/11] refactor to use no magic numbers --- init.lua | 2 +- lua/kickstart/plugins/debug.lua | 55 +++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/init.lua b/init.lua index 3adacdeef9f..3fcea5d11be 100644 --- a/init.lua +++ b/init.lua @@ -912,7 +912,7 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - -- require 'kickstart.plugins.debug', + require 'kickstart.plugins.debug', -- require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index e38d2ff0765..44f48273546 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -36,8 +36,9 @@ return { { 'B', function() + require 'dap.protocol' local dap = require 'dap' - -- Search for an existing breakpoing on this line in this buffer + -- Search for an existing breakpoint on this line in this buffer ---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder local function find_bp() local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()] @@ -55,30 +56,38 @@ return { -- Elicit customization via a UI prompt ---@param bp dap.SourceBreakpoint a breakpoint local function customize_bp(bp) - local fields = { - ('Condition: (%s)\n'):format(bp.condition), - ('Hit Condition: (%s)\n'):format(bp.hitCondition), - ('Log Message: (%s)\n'):format(bp.logMessage), + local props = { + ['Condition'] = { + value = bp.condition, + setter = function(v) + bp.condition = v + end, + }, + ['Hit Condition'] = { + value = bp.hitCondition, + setter = function(v) + bp.hitCondition = v + end, + }, + ['Log Message'] = { + value = bp.logMessage, + setter = function(v) + bp.logMessage = v + end, + }, } - vim.ui.select(fields, { - prompt = 'Edit breakpoint', + local menu_options = {} + for k, v in pairs(props) do + table.insert(menu_options, ('%s: %s'):format(k, v.value)) + end + vim.ui.select(menu_options, { + prompt = 'Edit Breakpoint', }, function(choice) - if choice == fields[1] then - bp.condition = vim.fn.input { - prompt = 'Condition: ', - default = bp.condition, - } - elseif choice == fields[2] then - bp.hitCondition = vim.fn.input { - prompt = 'Hit Condition: ', - default = bp.hitCondition, - } - elseif choice == fields[3] then - bp.logMessage = vim.fn.input { - prompt = 'Log Message: ', - default = bp.logMessage, - } - end + local prompt = (tostring(choice)):gsub(':.*', '') + props[prompt].setter(vim.fn.input { + prompt = ('[%s] '):format(prompt), + default = props[prompt].value, + }) -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint()) dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage) From 1d00e3f3f90fc55680726d663f0b57cfa80d919f Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Wed, 14 May 2025 03:03:10 -0700 Subject: [PATCH 03/11] revert testing change --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 3fcea5d11be..3adacdeef9f 100644 --- a/init.lua +++ b/init.lua @@ -912,7 +912,7 @@ require('lazy').setup({ -- Here are some example plugins that I've included in the Kickstart repository. -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- - require 'kickstart.plugins.debug', + -- require 'kickstart.plugins.debug', -- require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', From fac4966ab05510c4cfb710eaaf11e15ca3825eaa Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:31:34 -0700 Subject: [PATCH 04/11] lazily init empty breakpoint Instead of creating an empty object to fill, only create one if no match is found. Co-authored-by: Ori Perry <48057913+oriori1703@users.noreply.github.com> --- lua/kickstart/plugins/debug.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 44f48273546..671d73ebd64 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -38,21 +38,22 @@ return { function() require 'dap.protocol' local dap = require 'dap' + -- Search for an existing breakpoint on this line in this buffer ---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder local function find_bp() local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()] ---@type dap.SourceBreakpoint - local bp = { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' } for _, candidate in ipairs(buf_bps) do if candidate.line and candidate.line == vim.fn.line '.' then - bp = candidate - break + return candidate end end - return bp + + return { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' } end + -- Elicit customization via a UI prompt ---@param bp dap.SourceBreakpoint a breakpoint local function customize_bp(bp) From 97bebb657d74d1614542e89c017502646a9331f2 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:40:42 -0700 Subject: [PATCH 05/11] declare vim.ui.select opt `format_item` Co-authored-by: Ori Perry <48057913+oriori1703@users.noreply.github.com> --- lua/kickstart/plugins/debug.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 671d73ebd64..0b5170b27bb 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -78,13 +78,13 @@ return { }, } local menu_options = {} - for k, v in pairs(props) do - table.insert(menu_options, ('%s: %s'):format(k, v.value)) + for k, _ in pairs(props) do + table.insert(menu_options, k) end vim.ui.select(menu_options, { prompt = 'Edit Breakpoint', + format_item = function(item) return ('%s: %s'):format(item, props[item].value) end, }, function(choice) - local prompt = (tostring(choice)):gsub(':.*', '') props[prompt].setter(vim.fn.input { prompt = ('[%s] '):format(prompt), default = props[prompt].value, From 3739fc51ed593461a0af92f8df45cb1fb9d2ef51 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:41:05 -0700 Subject: [PATCH 06/11] handle cancellation Co-authored-by: Ori Perry <48057913+oriori1703@users.noreply.github.com> --- lua/kickstart/plugins/debug.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 0b5170b27bb..a4868b27516 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -85,6 +85,10 @@ return { prompt = 'Edit Breakpoint', format_item = function(item) return ('%s: %s'):format(item, props[item].value) end, }, function(choice) + if choice == nil then + -- User cancelled the selection + return + end props[prompt].setter(vim.fn.input { prompt = ('[%s] '):format(prompt), default = props[prompt].value, From 783c91f0e24d6508195f442e94953930c4e71c75 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:43:59 -0700 Subject: [PATCH 07/11] Remove unnecessary import --- lua/kickstart/plugins/debug.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index a4868b27516..80665b57245 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -36,7 +36,6 @@ return { { 'B', function() - require 'dap.protocol' local dap = require 'dap' -- Search for an existing breakpoint on this line in this buffer From 24088e59e9b8c5cdc3af4f96136ab547ab16ea2a Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:53:17 -0700 Subject: [PATCH 08/11] fix styleua issue --- lua/kickstart/plugins/debug.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 80665b57245..0f653e8c04a 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -52,7 +52,6 @@ return { return { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' } end - -- Elicit customization via a UI prompt ---@param bp dap.SourceBreakpoint a breakpoint local function customize_bp(bp) @@ -82,7 +81,9 @@ return { end vim.ui.select(menu_options, { prompt = 'Edit Breakpoint', - format_item = function(item) return ('%s: %s'):format(item, props[item].value) end, + format_item = function(item) + return ('%s: %s'):format(item, props[item].value) + end, }, function(choice) if choice == nil then -- User cancelled the selection From f8529309d2e7ea7a957402a6fc8b6ae0b80ed942 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 09:21:48 -0700 Subject: [PATCH 09/11] fix merge issue Co-authored-by: Ori Perry <48057913+oriori1703@users.noreply.github.com> --- lua/kickstart/plugins/debug.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 0f653e8c04a..e2c91366d2a 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -89,9 +89,10 @@ return { -- User cancelled the selection return end - props[prompt].setter(vim.fn.input { - prompt = ('[%s] '):format(prompt), - default = props[prompt].value, + props[choice].setter(vim.fn.input { + prompt = ('[%s] '):format(choice), + default = props[choice].value, + }) -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint()) From 74ed652b106e06f1af56ff832879d94cee2ee709 Mon Sep 17 00:00:00 2001 From: Brian Lehrer <661570+blehrer@users.noreply.github.com> Date: Fri, 4 Jul 2025 09:23:59 -0700 Subject: [PATCH 10/11] stylua --- lua/kickstart/plugins/debug.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index e2c91366d2a..9c51565fa06 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -89,10 +89,9 @@ return { -- User cancelled the selection return end - props[choice].setter(vim.fn.input { + props[choice].setter(vim.fn.input { prompt = ('[%s] '):format(choice), default = props[choice].value, - }) -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint()) From d5dc915d69aef09b7330a6a0958f2ddd82ccc230 Mon Sep 17 00:00:00 2001 From: Ori Perry Date: Sat, 28 Feb 2026 13:25:44 +0200 Subject: [PATCH 11/11] Fix stylua formatting --- lua/kickstart/plugins/debug.lua | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 9c51565fa06..5ff1b4b87fd 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -44,9 +44,7 @@ return { local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()] ---@type dap.SourceBreakpoint for _, candidate in ipairs(buf_bps) do - if candidate.line and candidate.line == vim.fn.line '.' then - return candidate - end + if candidate.line and candidate.line == vim.fn.line '.' then return candidate end end return { condition = '', logMessage = '', hitCondition = '', line = vim.fn.line '.' } @@ -58,21 +56,15 @@ return { local props = { ['Condition'] = { value = bp.condition, - setter = function(v) - bp.condition = v - end, + setter = function(v) bp.condition = v end, }, ['Hit Condition'] = { value = bp.hitCondition, - setter = function(v) - bp.hitCondition = v - end, + setter = function(v) bp.hitCondition = v end, }, ['Log Message'] = { value = bp.logMessage, - setter = function(v) - bp.logMessage = v - end, + setter = function(v) bp.logMessage = v end, }, } local menu_options = {} @@ -81,9 +73,7 @@ return { end vim.ui.select(menu_options, { prompt = 'Edit Breakpoint', - format_item = function(item) - return ('%s: %s'):format(item, props[item].value) - end, + format_item = function(item) return ('%s: %s'):format(item, props[item].value) end, }, function(choice) if choice == nil then -- User cancelled the selection