mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
fix(c_indents): fix expression leaking indents
This commit is contained in:
parent
474c59dcf1
commit
9161093fc7
3 changed files with 46 additions and 1 deletions
|
|
@ -6,9 +6,15 @@
|
||||||
(compound_literal_expression)
|
(compound_literal_expression)
|
||||||
(initializer_list)
|
(initializer_list)
|
||||||
(init_declarator)
|
(init_declarator)
|
||||||
(expression_statement)
|
|
||||||
] @indent.begin
|
] @indent.begin
|
||||||
|
|
||||||
|
; With current indent logic, if we capture expression_statement with @indent.begin
|
||||||
|
; It will be affected by _parent_ node with error subnodes deep down the tree
|
||||||
|
; So narrow indent capture to check for error inside expression statement only,
|
||||||
|
(expression_statement
|
||||||
|
(_) @indent.begin
|
||||||
|
";" @indent.end)
|
||||||
|
|
||||||
(
|
(
|
||||||
ERROR
|
ERROR
|
||||||
"for" "(" @indent.begin ";" ";" ")" @indent.end)
|
"for" "(" @indent.begin ";" ";" ")" @indent.end)
|
||||||
|
|
|
||||||
23
tests/indent/c/issue-4525.c
Normal file
23
tests/indent/c/issue-4525.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char *a = "a" "b" "c" D;
|
||||||
|
|
||||||
|
static int a, b, c;
|
||||||
|
a = b = c = 0;
|
||||||
|
|
||||||
|
static int d = 0, e = 0, f = 0;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
printf("String" PRIu64 "\n", (uint64_t)0);
|
||||||
|
printf("String" AND_ERROR_NODE "and string");
|
||||||
|
fflush(stdout);
|
||||||
|
a = 0; b = 0; c = 0;
|
||||||
|
int x = 0; int y = 0; int z = 0;
|
||||||
|
foo(1, 2);
|
||||||
|
x++;
|
||||||
|
a = b
|
||||||
|
= c
|
||||||
|
= d;
|
||||||
|
}
|
||||||
|
|
@ -73,5 +73,21 @@ describe("indent C:", function()
|
||||||
for _, line in ipairs { 10, 12, 14 } do
|
for _, line in ipairs { 10, 12, 14 } do
|
||||||
runner:new_line("if_else.c", { on_line = line, text = "{}", indent = 4 })
|
runner:new_line("if_else.c", { on_line = line, text = "{}", indent = 4 })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for _, info in ipairs {
|
||||||
|
{ 8, 0 },
|
||||||
|
{ 10, 0 },
|
||||||
|
{ 13, 4 },
|
||||||
|
{ 14, 4 },
|
||||||
|
{ 15, 4 },
|
||||||
|
{ 16, 4 },
|
||||||
|
{ 17, 4 },
|
||||||
|
{ 18, 4 },
|
||||||
|
{ 20, 8 },
|
||||||
|
{ 21, 8 },
|
||||||
|
{ 22, 4 },
|
||||||
|
} do
|
||||||
|
runner:new_line("issue-4525.c", { on_line = info[1], text = "x++;", indent = info[2] })
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue