mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
indents(c): add zero_indent for #if
This commit is contained in:
parent
616dc885fc
commit
fd5a551d7c
7 changed files with 18 additions and 13 deletions
|
|
@ -35,6 +35,7 @@ local get_indents = tsutils.memoize_by_buf_tick(function(bufnr, root, lang)
|
|||
branch = {},
|
||||
ignore = {},
|
||||
aligned_indent = {},
|
||||
zero_indent = {},
|
||||
}
|
||||
|
||||
for name, node, metadata in queries.iter_captures(bufnr, "indents", root, lang) do
|
||||
|
|
@ -88,6 +89,10 @@ function M.get_indent(lnum)
|
|||
-- tracks to ensure multiple indent levels are not applied for same line
|
||||
local is_processed_by_row = {}
|
||||
|
||||
if q.zero_indent[node:id()] then
|
||||
return 0
|
||||
end
|
||||
|
||||
while node do
|
||||
-- do 'autoindent' if not marked as @indent
|
||||
if not q.indent[node:id()] and q.auto[node:id()] and node:start() < lnum - 1 and lnum - 1 <= node:end_() then
|
||||
|
|
|
|||
|
|
@ -26,16 +26,20 @@
|
|||
|
||||
(compound_statement "}" @indent_end)
|
||||
|
||||
[
|
||||
"else"
|
||||
")"
|
||||
"}"
|
||||
(statement_identifier)
|
||||
] @branch
|
||||
|
||||
[
|
||||
"#define"
|
||||
"#ifdef"
|
||||
"#if"
|
||||
"#else"
|
||||
"else"
|
||||
"#endif"
|
||||
")"
|
||||
"}"
|
||||
] @branch
|
||||
] @zero_indent
|
||||
|
||||
[
|
||||
(preproc_arg)
|
||||
|
|
@ -47,7 +51,7 @@
|
|||
([(argument_list) (parameter_list)] @aligned_indent
|
||||
(#set! "delimiter" "()"))
|
||||
|
||||
([ (ERROR) (comment) ] @aligned_indent
|
||||
((comment) @aligned_indent
|
||||
(#lua-match? @aligned_indent "^/\*"))
|
||||
((comment) @ignore
|
||||
(#lua-match? @ignore "^//"))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,3 @@ void foo(int a,
|
|||
void foo(int a,
|
||||
int b
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,3 @@
|
|||
void foo(int *x, int y) {
|
||||
*x = y;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
|
|
|
|||
2
tests/indent/c/unfinished_comment.c
Normal file
2
tests/indent/c/unfinished_comment.c
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/*
|
||||
*
|
||||
|
|
@ -13,7 +13,7 @@ describe("indent C:", function()
|
|||
runner:whole_file(".", {
|
||||
expected_failures = {
|
||||
"./preproc_func.c",
|
||||
"./label.c",
|
||||
"./unfinished_comment.c",
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe("indent C++:", function()
|
|||
expected_failures = {
|
||||
-- C
|
||||
"c/preproc_func.c",
|
||||
"c/label.c",
|
||||
"c/unfinished_comment.c",
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue