Skip to content

Commit 40ddd36

Browse files
phanenandrewferrier
authored andcommitted
feat: Support field_expression special case for C
1 parent 9165c70 commit 40ddd36

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lua/debugprint/filetypes.lua

+15
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ return {
8080
right = '\\n");',
8181
mid_var = '%d\\n", ',
8282
right_var = ");",
83+
find_treesitter_variable = function(node)
84+
if node:type() == "field_expression" then
85+
return vim.treesitter.get_node_text(node, 0)
86+
elseif
87+
node:parent()
88+
and node:parent():type() == "field_expression"
89+
and node:prev_named_sibling()
90+
then
91+
return vim.treesitter.get_node_text(node:parent(), 0)
92+
elseif node:type() == "identifier" then
93+
return vim.treesitter.get_node_text(node, 0)
94+
else
95+
return nil
96+
end
97+
end,
8398
},
8499
["cmake"] = {
85100
left = 'message(DEBUG "',

tests/debugprint.lua

+23
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,29 @@ describe("can handle treesitter identifiers", function()
11971197
assert.equals(notify_message, nil)
11981198
end)
11991199

1200+
it("special case dot expression (c)", function()
1201+
debugprint.setup()
1202+
1203+
init_file({
1204+
"int main() {",
1205+
"person.year = 1984;",
1206+
"}",
1207+
}, "c", 2, 10)
1208+
1209+
feedkeys("g?v")
1210+
1211+
check_lines({
1212+
"int main() {",
1213+
"person.year = 1984;",
1214+
'fprintf(stderr, "DEBUGPRINT[1]: 45.c:2: person.year=%d\\n", person.year);',
1215+
"}",
1216+
})
1217+
1218+
assert.are.same(vim.api.nvim_win_get_cursor(0), { 2, 10 })
1219+
1220+
assert.equals(notify_message, nil)
1221+
end)
1222+
12001223
it("non-special case variable (python)", function()
12011224
debugprint.setup()
12021225

0 commit comments

Comments
 (0)