Skip to content

Commit a814776

Browse files
author
Andrew Ferrier
committed
feat: Add 'display_counter' toggle - closes #32
1 parent ec863ee commit a814776

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ end)
178178
| ------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
179179
| `create_keymaps` | `true` | Creates default keymappings - see above |
180180
| `move_to_debugline` | `false` | When adding a debug line, moves the cursor to that line |
181+
| `display_counter` | `true` | Whether to display/include the monotonically increasing counter in each debug message added |
181182
| `filetypes` | See below | Custom filetypes - see below |
182183
| `ignore_treesitter` | `false` | Never use treesitter to find a variable under the cursor, always prompt for it - overrides the same setting on `debugprint()` if set to true |
183184
| `print_tag` | `DEBUGPRINT` | The string inserted into each print statement, which can be used to uniquely identify statements inserted by `debugprint`. |

lua/debugprint/init.lua

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local global_opts
77
GLOBAL_OPTION_DEFAULTS = {
88
create_keymaps = true,
99
create_commands = true,
10+
display_counter = true,
1011
move_to_debugline = false,
1112
ignore_treesitter = false,
1213
filetypes = require("debugprint.filetypes"),
@@ -26,9 +27,14 @@ local debuginfo = function(variable_name)
2627
counter = counter + 1
2728

2829
local line = global_opts.print_tag
29-
.. "["
30+
31+
if global_opts.display_counter then
32+
line = line .. "["
3033
.. counter
31-
.. "]: "
34+
.. "]"
35+
end
36+
37+
line = line .. ": "
3238
.. vim.fn.expand("%:t")
3339
.. ":"
3440
.. current_line
@@ -243,6 +249,7 @@ M.setup = function(opts)
243249
vim.validate({
244250
create_keymaps = { global_opts.create_keymaps, "boolean" },
245251
create_commands = { global_opts.create_commands, "boolean" },
252+
display_counter = { global_opts.move_to_debugline, "boolean" },
246253
move_to_debugline = { global_opts.move_to_debugline, "boolean" },
247254
ignore_treesitter = { global_opts.ignore_treesitter, "boolean" },
248255
filetypes = { global_opts.filetypes, "table" },

tests/debugprint.lua

+38
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,41 @@ describe("delete lines command", function()
10361036
})
10371037
end)
10381038
end)
1039+
1040+
describe("don't display counter", function()
1041+
before_each(function()
1042+
debugprint.setup({ ignore_treesitter = true, display_counter = false })
1043+
end)
1044+
1045+
it("basic statement", function()
1046+
local filename = init_file({
1047+
"foo",
1048+
"bar",
1049+
}, "lua", 1, 0)
1050+
1051+
feedkeys("g?p")
1052+
1053+
check_lines({
1054+
"foo",
1055+
"print('DEBUGPRINT: " .. filename .. ":1')",
1056+
"bar",
1057+
})
1058+
end)
1059+
1060+
it("can insert a variable statement below", function()
1061+
local filename = init_file({
1062+
"foo",
1063+
"bar",
1064+
}, "lua", 1, 0)
1065+
1066+
feedkeys("g?vbanana<CR>")
1067+
1068+
check_lines({
1069+
"foo",
1070+
"print('DEBUGPRINT: "
1071+
.. filename
1072+
.. ":1: banana=' .. vim.inspect(banana))",
1073+
"bar",
1074+
})
1075+
end)
1076+
end)

0 commit comments

Comments
 (0)