Skip to content

Commit acd90b4

Browse files
author
Andrew Ferrier
committed
fix: Check filetype before prompt for variable
1 parent 398f3f0 commit acd90b4

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

lua/debugprint/init.lua

+15-7
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ local debuginfo = function(variable_name)
2828
return line
2929
end
3030

31-
local get_fix = function(filetype)
32-
if vim.tbl_contains(vim.tbl_keys(opts.filetypes), filetype) then
33-
return opts.filetypes[filetype]
34-
else
31+
local filetype_configured = function()
32+
local filetype =
33+
vim.api.nvim_get_option_value("filetype", { scope = "local" })
34+
35+
if not vim.tbl_contains(vim.tbl_keys(opts.filetypes), filetype) then
3536
vim.notify(
3637
"Don't have debugprint configuration for filetype " .. filetype,
3738
vim.log.levels.WARN
3839
)
39-
return nil
40+
return false
41+
else
42+
return true
4043
end
4144
end
4245

@@ -62,8 +65,9 @@ local debugprint_logic = function(o)
6265
})
6366

6467
local current_line = vim.api.nvim_win_get_cursor(0)[1]
65-
local filetype = vim.api.nvim_get_option_value("filetype", {})
66-
local fixes = get_fix(filetype)
68+
local filetype =
69+
vim.api.nvim_get_option_value("filetype", { scope = "local" })
70+
local fixes = opts.filetypes[filetype]
6771

6872
if fixes == nil then
6973
return
@@ -111,6 +115,10 @@ end
111115

112116
local debugprint_cache = function(o)
113117
if o and o.prerepeat == true then
118+
if not filetype_configured() then
119+
return
120+
end
121+
114122
if o.variable == true then
115123
o.variable_name = vim.fn.input("Variable name: ")
116124
end

tests/debugprint.lua

+17
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ describe("can do various file types", function()
208208
"bar",
209209
})
210210
end)
211+
212+
it("don't prompt for a variable name with an unknown filetype", function()
213+
set_lines({
214+
"foo",
215+
"bar",
216+
})
217+
218+
write_file("foo")
219+
vim.api.nvim_win_set_cursor(0, { 1, 0 })
220+
feedkeys("dQp")
221+
assert.are.same("Don't have debugprint configuration for filetype foo", notify_message)
222+
223+
check_lines({
224+
"foo",
225+
"bar",
226+
})
227+
end)
211228
end)
212229

213230
describe("can do indenting correctly", function()

0 commit comments

Comments
 (0)