Skip to content

Commit 48505a2

Browse files
committed
fix!: Deprecation warning calling debugprint() directly - closes #99
1 parent 5bf6cec commit 48505a2

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,14 @@ they are used to convert sections to ROT-13, which most folks don't use.
176176

177177
> [!WARNING]
178178
> *Note*: as of version 2.0.0, the old mechanism of configuring keymaps/commands
179-
> which specifically allowed for mapping directly to
179+
> which specifically allowed for creating your own keymaps using
180+
> `vim.keymap.set()` directly to
180181
> `require('debugprint').debugprint(...)` is no longer officially supported or
181182
> documented. This is primarily because of [confusion](https://github.com/andrewferrier/debugprint.nvim/issues/44#issuecomment-1896405231) which arose over how to do
182-
> this mapping. Existing mappings performed this way are likely to continue to
183-
> work for some time. You should, however, migrate over to the new method outlined
184-
> above. If this doesn't give you the flexibility to map how you wish for some
183+
> this mapping. Existing mappings performed this way may continue to work but
184+
> will produce a deprecation warning.
185+
> You should migrate to the new configuration-based method outlined
186+
> [above](https://github.com/andrewferrier/debugprint.nvim?tab=readme-ov-file#keymappings-and-commands). If this doesn't give you the flexibility to map how you wish for some
185187
> reason, please open an
186188
> [issue](https://github.com/andrewferrier/debugprint.nvim/issues/new).
187189

lua/debugprint/options.lua

+7
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ M.get_and_validate_function_opts = function(opts)
207207
assert(not (func_opts.motion and func_opts.insert))
208208
assert(not (func_opts.motion and func_opts.variable))
209209

210+
if not func_opts._skip_warning then
211+
vim.notify_once(
212+
"debugprint.nvim: mapping directly to the debugprint() function is deprecated and no longer supported. You are *STRONGLY RECOMMENDED* to use the inbuilt mapping approach: https://github.com/andrewferrier/debugprint.nvim?tab=readme-ov-file#mapping-deprecation",
213+
vim.log.levels.WARN
214+
)
215+
end
216+
210217
return func_opts
211218
end
212219

lua/debugprint/setup.lua

+15-6
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,29 @@ end
2727
M.map_keys_and_commands = function(global_opts)
2828
map_key("n", global_opts.keymaps.normal.plain_below, {
2929
callback = function()
30-
debugprint.debugprint({})
30+
debugprint.debugprint({ _skip_warning = true })
3131
end,
3232
desc = "Plain debug below current line",
3333
})
3434

3535
map_key("n", global_opts.keymaps.normal.plain_above, {
3636
callback = function()
37-
debugprint.debugprint({ above = true })
37+
debugprint.debugprint({ _skip_warning = true, above = true })
3838
end,
3939
desc = "Plain debug above current line",
4040
})
4141

4242
map_key("n", global_opts.keymaps.normal.variable_below, {
4343
callback = function()
44-
debugprint.debugprint({ variable = true })
44+
debugprint.debugprint({ _skip_warning = true, variable = true })
4545
end,
4646
desc = "Variable debug below current line",
4747
})
4848

4949
map_key("n", global_opts.keymaps.normal.variable_above, {
5050
callback = function()
5151
debugprint.debugprint({
52+
_skip_warning = true,
5253
above = true,
5354
variable = true,
5455
})
@@ -59,6 +60,7 @@ M.map_keys_and_commands = function(global_opts)
5960
map_key("n", global_opts.keymaps.normal.variable_below_alwaysprompt, {
6061
callback = function()
6162
debugprint.debugprint({
63+
_skip_warning = true,
6264
variable = true,
6365
ignore_treesitter = true,
6466
})
@@ -69,6 +71,7 @@ M.map_keys_and_commands = function(global_opts)
6971
map_key("n", global_opts.keymaps.normal.variable_above_alwaysprompt, {
7072
callback = function()
7173
debugprint.debugprint({
74+
_skip_warning = true,
7275
above = true,
7376
variable = true,
7477
ignore_treesitter = true,
@@ -79,7 +82,10 @@ M.map_keys_and_commands = function(global_opts)
7982

8083
map_key("n", global_opts.keymaps.normal.textobj_below, {
8184
callback = function()
82-
return debugprint.debugprint({ motion = true })
85+
return debugprint.debugprint({
86+
_skip_warning = true,
87+
motion = true,
88+
})
8389
end,
8490
expr = true,
8591
desc = "Text-obj-selected variable debug below current line",
@@ -88,6 +94,7 @@ M.map_keys_and_commands = function(global_opts)
8894
map_key("n", global_opts.keymaps.normal.textobj_above, {
8995
callback = function()
9096
return debugprint.debugprint({
97+
_skip_warning = true,
9198
motion = true,
9299
above = true,
93100
})
@@ -98,14 +105,15 @@ M.map_keys_and_commands = function(global_opts)
98105

99106
map_key("i", global_opts.keymaps.insert.plain, {
100107
callback = function()
101-
debugprint.debugprint({ insert = true })
108+
debugprint.debugprint({ _skip_warning = true, insert = true })
102109
end,
103110
desc = "Plain debug in-place",
104111
})
105112

106113
map_key("i", global_opts.keymaps.insert.variable, {
107114
callback = function()
108115
debugprint.debugprint({
116+
_skip_warning = true,
109117
insert = true,
110118
variable = true,
111119
ignore_treesitter = true,
@@ -116,14 +124,15 @@ M.map_keys_and_commands = function(global_opts)
116124

117125
map_key("x", global_opts.keymaps.visual.variable_below, {
118126
callback = function()
119-
debugprint.debugprint({ variable = true })
127+
debugprint.debugprint({ _skip_warning = true, variable = true })
120128
end,
121129
desc = "Variable debug below current line",
122130
})
123131

124132
map_key("x", global_opts.keymaps.visual.variable_above, {
125133
callback = function()
126134
debugprint.debugprint({
135+
_skip_warning = true,
127136
above = true,
128137
variable = true,
129138
})

tests/debugprint.lua

+32
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,38 @@ describe("handle deprecated options, create_keymaps=true", function()
21692169
end)
21702170
end)
21712171

2172+
describe("handle deprecated options, direct mapping", function()
2173+
before_each(function()
2174+
debugprint.setup()
2175+
2176+
vim.keymap.set("n", "g?t", function()
2177+
debugprint.debugprint({})
2178+
end)
2179+
end)
2180+
2181+
after_each(teardown)
2182+
2183+
it("basic", function()
2184+
local filename = init_file({
2185+
"foo",
2186+
"bar",
2187+
}, "lua", 1, 0)
2188+
2189+
feedkeys("g?t")
2190+
2191+
check_lines({
2192+
"foo",
2193+
"print('DEBUGPRINT[1]: " .. filename .. ":1 (after foo)')",
2194+
"bar",
2195+
})
2196+
2197+
print(notify_message)
2198+
2199+
assert.True(notify_message:find("mapping directly") > 0)
2200+
assert.True(notify_message:find("is deprecated") > 0)
2201+
end)
2202+
end)
2203+
21722204
describe("unmodifiable buffer", function()
21732205
before_each(function()
21742206
debugprint.setup()

0 commit comments

Comments
 (0)