Skip to content

Commit 87fe216

Browse files
committed
refactor to use no magic numbers
1 parent 479cb6e commit 87fe216

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ require('lazy').setup({
973973
-- Here are some example plugins that I've included in the Kickstart repository.
974974
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
975975
--
976-
-- require 'kickstart.plugins.debug',
976+
require 'kickstart.plugins.debug',
977977
-- require 'kickstart.plugins.indent_line',
978978
-- require 'kickstart.plugins.lint',
979979
-- require 'kickstart.plugins.autopairs',

lua/kickstart/plugins/debug.lua

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ return {
6464
{
6565
'<leader>B',
6666
function()
67+
require 'dap.protocol'
6768
local dap = require 'dap'
68-
-- Search for an existing breakpoing on this line in this buffer
69+
-- Search for an existing breakpoint on this line in this buffer
6970
---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder
7071
local function find_bp()
7172
local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()]
@@ -83,30 +84,38 @@ return {
8384
-- Elicit customization via a UI prompt
8485
---@param bp dap.SourceBreakpoint a breakpoint
8586
local function customize_bp(bp)
86-
local fields = {
87-
('Condition: (%s)\n'):format(bp.condition),
88-
('Hit Condition: (%s)\n'):format(bp.hitCondition),
89-
('Log Message: (%s)\n'):format(bp.logMessage),
87+
local props = {
88+
['Condition'] = {
89+
value = bp.condition,
90+
setter = function(v)
91+
bp.condition = v
92+
end,
93+
},
94+
['Hit Condition'] = {
95+
value = bp.hitCondition,
96+
setter = function(v)
97+
bp.hitCondition = v
98+
end,
99+
},
100+
['Log Message'] = {
101+
value = bp.logMessage,
102+
setter = function(v)
103+
bp.logMessage = v
104+
end,
105+
},
90106
}
91-
vim.ui.select(fields, {
92-
prompt = 'Edit breakpoint',
107+
local menu_options = {}
108+
for k, v in pairs(props) do
109+
table.insert(menu_options, ('%s: %s'):format(k, v.value))
110+
end
111+
vim.ui.select(menu_options, {
112+
prompt = 'Edit Breakpoint',
93113
}, function(choice)
94-
if choice == fields[1] then
95-
bp.condition = vim.fn.input {
96-
prompt = 'Condition: ',
97-
default = bp.condition,
98-
}
99-
elseif choice == fields[2] then
100-
bp.hitCondition = vim.fn.input {
101-
prompt = 'Hit Condition: ',
102-
default = bp.hitCondition,
103-
}
104-
elseif choice == fields[3] then
105-
bp.logMessage = vim.fn.input {
106-
prompt = 'Log Message: ',
107-
default = bp.logMessage,
108-
}
109-
end
114+
local prompt = (tostring(choice)):gsub(':.*', '')
115+
props[prompt].setter(vim.fn.input {
116+
prompt = ('[%s] '):format(prompt),
117+
default = props[prompt].value,
118+
})
110119

111120
-- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
112121
dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage)

0 commit comments

Comments
 (0)