Skip to content

Commit 775de28

Browse files
committed
feat: Use a default value for variable input - closes #59
1 parent 8a6da16 commit 775de28

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

lua/debugprint/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ local get_variable_name = function(opts)
220220
end
221221

222222
if variable_name == nil then
223-
variable_name = vim.fn.input("Variable name: ")
223+
local word_under_cursor = vim.fn.expand("<cword>")
224+
variable_name = vim.fn.input("Variable name: ", word_under_cursor)
224225

225226
if variable_name == nil or variable_name == "" then
226227
vim.notify("No variable name entered.", vim.log.levels.WARN)

tests/debugprint.lua

+27-10
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,30 @@ describe("can do variable debug statement insertion", function()
280280

281281
after_each(teardown)
282282

283+
it("can insert a variable statement below using the default value", function()
284+
local filename = init_file({
285+
"foo",
286+
"bar",
287+
}, "lua", 1, 0)
288+
289+
feedkeys("g?v<CR>")
290+
291+
check_lines({
292+
"foo",
293+
"print('DEBUGPRINT[1]: "
294+
.. filename
295+
.. ":1: foo=' .. vim.inspect(foo))",
296+
"bar",
297+
})
298+
end)
299+
283300
it("can insert a variable statement below", function()
284301
local filename = init_file({
285302
"foo",
286303
"bar",
287304
}, "lua", 1, 0)
288305

289-
feedkeys("g?vbanana<CR>")
306+
feedkeys("g?v<BS><BS><BS>banana<CR>")
290307

291308
check_lines({
292309
"foo",
@@ -303,7 +320,7 @@ describe("can do variable debug statement insertion", function()
303320
"bar",
304321
}, "lua", 1, 0)
305322

306-
feedkeys("g?Vbanana<CR>")
323+
feedkeys("g?V<BS><BS><BS>banana<CR>")
307324

308325
check_lines({
309326
"print('DEBUGPRINT[1]: "
@@ -320,7 +337,7 @@ describe("can do variable debug statement insertion", function()
320337
"bar",
321338
}, "lua", 1, 0)
322339

323-
feedkeys("g?v<CR>")
340+
feedkeys("g?v<BS><BS><BS><CR>")
324341
assert.are.same("No variable name entered.", notify_message)
325342

326343
check_lines({
@@ -358,7 +375,7 @@ describe("can do various file types", function()
358375
"bar",
359376
}, "vim", 1, 0)
360377

361-
feedkeys("g?vbanana<CR>")
378+
feedkeys("g?v<BS><BS><BS>banana<CR>")
362379

363380
check_lines({
364381
"foo",
@@ -521,7 +538,7 @@ describe("add custom filetype with setup()", function()
521538
"bar",
522539
}, "wibble", 1, 0)
523540

524-
feedkeys("g?vapple<CR>")
541+
feedkeys("g?v<BS><BS><BS>apple<CR>")
525542

526543
check_lines({
527544
"foo",
@@ -714,9 +731,9 @@ describe("can repeat", function()
714731
"bar",
715732
}, "lua", 1, 0)
716733

717-
feedkeys("g?vbanana<CR>")
734+
feedkeys("g?v<BS><BS><BS>banana<CR>")
718735
feedkeys(".")
719-
feedkeys("g?Vapple<CR>")
736+
feedkeys("g?V<BS><BS><BS>apple<CR>")
720737
feedkeys(".")
721738

722739
check_lines({
@@ -822,7 +839,7 @@ describe("can handle treesitter identifiers", function()
822839
"end",
823840
}, "lua", 2, 9)
824841

825-
feedkeys("g?vapple<CR>")
842+
feedkeys("g?v<BS><BS><BS>apple<CR>")
826843

827844
check_lines({
828845
"function x()",
@@ -853,7 +870,7 @@ describe("can handle treesitter identifiers", function()
853870
end, {
854871
expr = true,
855872
})
856-
feedkeys("zxaapple<CR>")
873+
feedkeys("zxa<BS><BS><BS>apple<CR>")
857874

858875
check_lines({
859876
"function x()",
@@ -1295,7 +1312,7 @@ describe("don't display counter", function()
12951312
"bar",
12961313
}, "lua", 1, 0)
12971314

1298-
feedkeys("g?vbanana<CR>")
1315+
feedkeys("g?v<BS><BS><BS>banana<CR>")
12991316

13001317
check_lines({
13011318
"foo",

0 commit comments

Comments
 (0)