aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/c/indents.scm
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-12 09:54:30 -0600
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit692b051b09935653befdb8f7ba8afdb640adf17b (patch)
tree167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/c/indents.scm
parentfeat(c-family): inherit injections (diff)
downloadnvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/c/indents.scm')
-rw-r--r--runtime/queries/c/indents.scm99
1 files changed, 99 insertions, 0 deletions
diff --git a/runtime/queries/c/indents.scm b/runtime/queries/c/indents.scm
new file mode 100644
index 000000000..1932ce8d6
--- /dev/null
+++ b/runtime/queries/c/indents.scm
@@ -0,0 +1,99 @@
+[
+ (compound_statement)
+ (field_declaration_list)
+ (case_statement)
+ (enumerator_list)
+ (compound_literal_expression)
+ (initializer_list)
+ (init_declarator)
+] @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
+ "for"
+ "(" @indent.begin
+ ";"
+ ";"
+ ")" @indent.end)
+
+((for_statement
+ body: (_) @_body) @indent.begin
+ (#not-kind-eq? @_body "compound_statement"))
+
+(while_statement
+ condition: (_) @indent.begin)
+
+((while_statement
+ body: (_) @_body) @indent.begin
+ (#not-kind-eq? @_body "compound_statement"))
+
+((if_statement)
+ .
+ (ERROR
+ "else" @indent.begin))
+
+(if_statement
+ condition: (_) @indent.begin)
+
+; Supports if without braces (but not both if-else without braces)
+(if_statement
+ consequence: (_
+ ";" @indent.end) @_consequence
+ (#not-kind-eq? @_consequence "compound_statement")
+ alternative: (else_clause
+ "else" @indent.branch
+ [
+ (if_statement
+ (compound_statement) @indent.dedent)? @indent.dedent
+ (compound_statement)? @indent.dedent
+ (_)? @indent.dedent
+ ])?) @indent.begin
+
+(else_clause
+ (_
+ .
+ "{" @indent.branch))
+
+(compound_statement
+ "}" @indent.end)
+
+[
+ ")"
+ "}"
+ (statement_identifier)
+] @indent.branch
+
+[
+ "#define"
+ "#ifdef"
+ "#ifndef"
+ "#elif"
+ "#if"
+ "#else"
+ "#endif"
+] @indent.zero
+
+[
+ (preproc_arg)
+ (string_literal)
+] @indent.ignore
+
+((ERROR
+ (parameter_declaration)) @indent.align
+ (#set! indent.open_delimiter "(")
+ (#set! indent.close_delimiter ")"))
+
+([
+ (argument_list)
+ (parameter_list)
+] @indent.align
+ (#set! indent.open_delimiter "(")
+ (#set! indent.close_delimiter ")"))
+
+(comment) @indent.auto