Skip to content

Commit 48d5f39

Browse files
author
Andrew Ferrier
committed
fix: Handle no variable name
1 parent cdb6687 commit 48d5f39

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lua/debugprint/init.lua

+8
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ M.debugprint_cache = function(opts)
138138

139139
if opts.variable_name == nil then
140140
opts.variable_name = vim.fn.input("Variable name: ")
141+
142+
if opts.variable_name == nil or opts.variable_name == "" then
143+
vim.notify(
144+
"No variable name entered.",
145+
vim.log.levels.WARN
146+
)
147+
return
148+
end
141149
end
142150
end
143151

tests/debugprint.lua

+18
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ describe("can do variable debug statement insertion", function()
144144
"bar",
145145
})
146146
end)
147+
148+
it("entering no name gives an error", function()
149+
local filename = init_file({
150+
"foo",
151+
"bar",
152+
}, "lua", 1, 0)
153+
154+
feedkeys("g?v<CR>")
155+
assert.are.same(
156+
"No variable name entered.",
157+
notify_message
158+
)
159+
160+
check_lines({
161+
"foo",
162+
"bar",
163+
})
164+
end)
147165
end)
148166

149167
describe("can do various file types", function()

0 commit comments

Comments
 (0)