Skip to content

Commit f9b9b87

Browse files
committed
fix: g?v for comments in lua
1 parent bb6d1c9 commit f9b9b87

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lua/debugprint/utils.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ M.find_treesitter_variable = function()
127127
return nil
128128
else
129129
local node_type = node:type()
130-
local parent_node_type = node:parent():type()
130+
local parent_node_type
131+
132+
if node:parent() ~= nil then
133+
-- This check is necessary; it triggers for example in comments in
134+
-- lua code
135+
parent_node_type = node:parent():type()
136+
end
131137

132138
local variable_name
133139

tests/debugprint.lua

+19
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,25 @@ if vim.fn.has("nvim-0.9.0") == 1 then
16371637
"</html>",
16381638
})
16391639
end)
1640+
1641+
it("comment in lua", function()
1642+
local filename = init_file({
1643+
"x = 3",
1644+
"-- abc",
1645+
"a = 2",
1646+
}, "lua", 2, 4)
1647+
1648+
feedkeys("g?v<CR>")
1649+
1650+
check_lines({
1651+
"x = 3",
1652+
"-- abc",
1653+
"print('DEBUGPRINT[1]: "
1654+
.. filename
1655+
.. ":2: abc=' .. vim.inspect(abc))",
1656+
"a = 2",
1657+
})
1658+
end)
16401659
end)
16411660
end
16421661

0 commit comments

Comments
 (0)