Skip to content

Commit c8b644c

Browse files
author
Andrew Ferrier
committed
fix: Support variables in sh
1 parent 6becfae commit c8b644c

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lua/debugprint/utils.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ M.find_treesitter_variable = function()
2121
local node_type = node:type()
2222
local variable_name = vim.treesitter.query.get_node_text(node, 0)
2323

24-
if node_type ~= "identifier" then
25-
return nil
26-
else
24+
-- lua -> identifier
25+
-- sh -> variable_name
26+
if node_type == "identifier" or node_type == "variable_name" then
2727
return variable_name
28+
else
29+
return nil
2830
end
2931
end
3032
end

tests/debugprint.lua

+19-2
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ describe("can handle treesitter identifiers", function()
635635
"end",
636636
}, "lua", 2, 10)
637637

638-
feedkeys("g?v<CR>")
638+
feedkeys("g?v")
639639

640640
check_lines({
641641
"function x()",
@@ -646,7 +646,24 @@ describe("can handle treesitter identifiers", function()
646646
"end",
647647
})
648648

649-
assert.are.same(vim.api.nvim_win_get_cursor(0), { 3, 4 })
649+
assert.are.same(vim.api.nvim_win_get_cursor(0), { 2, 10 })
650+
end)
651+
652+
it("standard (bash)", function()
653+
debugprint.setup({})
654+
655+
local filename = init_file({
656+
"XYZ=123",
657+
}, "sh", 1, 1)
658+
659+
feedkeys("g?v")
660+
661+
check_lines({
662+
"XYZ=123",
663+
'echo "DEBUGPRINT[1]: ' .. filename .. ':1: XYZ=${XYZ}"',
664+
})
665+
666+
assert.are.same(vim.api.nvim_win_get_cursor(0), { 1, 1 })
650667
end)
651668

652669
it("non-identifier", function()

0 commit comments

Comments
 (0)