From 479cb6e4d9202200502124d2e9b433bad147330c 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 | 53 +++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 753cb0ce..ec5ff5a1 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -64,9 +64,58 @@ return { { 'B', function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') + 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: Set Breakpoint', + desc = 'Debug: Edit Breakpoint', }, -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. { From 87fe216eebab0780feb190a8fb935661d1847499 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 b98ffc61..871396b8 100644 --- a/init.lua +++ b/init.lua @@ -973,7 +973,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 ec5ff5a1..55c5ee1d 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -64,8 +64,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()] @@ -83,30 +84,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 8bd125f45a61b4e724d534da1349c20afb63598a 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 871396b8..b98ffc61 100644 --- a/init.lua +++ b/init.lua @@ -973,7 +973,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 9a66c746232a5f6d2ef72897e93564a3b291a0c4 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 55c5ee1d..5a584bde 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -66,21 +66,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 c44ae63f043283899ed1654d4915c4416c441fb7 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 5a584bde..2857d401 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -106,13 +106,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 6246e578732bfb2499b3159fca3cb869c89aa43e 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 2857d401..2e40d579 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -113,6 +113,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 f81509ae9ec10922132e7cd5a275e0507d364ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Calla=20Alarc=C3=B3n?= Date: Thu, 22 May 2025 23:10:04 +0200 Subject: [PATCH 07/11] Update remaining Mason's old address (#1530) --- lua/kickstart/plugins/debug.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 2e40d579..5c8cc73e 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -18,7 +18,7 @@ return { 'nvim-neotest/nvim-nio', -- Installs the debug adapters for you - 'williamboman/mason.nvim', + 'mason-org/mason.nvim', 'jay-babu/mason-nvim-dap.nvim', -- Add your own debuggers here From 42ae4216fcd9e8957c0e18a78c1b8c7e5792b88b 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 08/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 5c8cc73e..871dd461 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -64,7 +64,6 @@ return { { 'B', function() - require 'dap.protocol' local dap = require 'dap' -- Search for an existing breakpoint on this line in this buffer From d4bb4c01e386f8248502d291193a74efccad4db9 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 09/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 871dd461..eab0a958 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -80,7 +80,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) @@ -110,7 +109,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 bc31ee1faa8c7d5d7028cc18a28c6d346e787bb1 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 10/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 eab0a958..4fe9a5af 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -117,9 +117,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 0d093a7ed445c672deb32c77faef23dbf3a04fa9 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 11/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 4fe9a5af..05ad377d 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -117,10 +117,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())