Debian Codegraph @

runtime/queries/cairo/indents.scm

raw symbols SCIP
1 [
2 (use_list)
3 (block)
4 (match_block)
5 (arguments)
6 (parameters)
7 (declaration_list)
8 (field_declaration_list)
9 (field_initializer_list)
10 (struct_pattern)
11 (tuple_pattern)
12 (unit_expression)
13 (enum_variant_list)
14 (call_expression)
15 (binary_expression)
16 (field_expression)
17 (tuple_expression)
18 (array_expression)
19
20 (token_tree)
21 ] @indent
22
23 [
24 "}"
25 "]"
26 ")"
27 ] @outdent
28
29 ; Indent the right side of assignments.
30 ; The #not-same-line? predicate is required to prevent an extra indent for e.g.
31 ; an else-clause where the previous if-clause starts on the same line as the assignment.
32 (assignment_expression
33 .
34 (_) @expr-start
35 right: (_) @indent
36 (#not-same-line? @indent @expr-start)
37
38 )
39 (compound_assignment_expr
40 .
41 (_) @expr-start
42 right: (_) @indent
43 (#not-same-line? @indent @expr-start)
44
45 )
46 (let_declaration
47 "let" @expr-start
48 value: (_) @indent
49 alternative: (_)? @indent
50 (#not-same-line? @indent @expr-start)
51
52 )
53 (let_condition
54 .
55 (_) @expr-start
56 value: (_) @indent
57 (#not-same-line? @indent @expr-start)
58
59 )
60 (if_expression
61 .
62 (_) @expr-start
63 condition: (_) @indent
64 (#not-same-line? @indent @expr-start)
65
66 )
67 (field_pattern
68 .
69 (_) @expr-start
70 pattern: (_) @indent
71 (#not-same-line? @indent @expr-start)
72
73 )
74 ; Indent type aliases that span multiple lines, similar to
75 ; regular assignment expressions
76 (type_item
77 .
78 (_) @expr-start
79 type: (_) @indent
80 (#not-same-line? @indent @expr-start)
81
82 )
83
84 ; Some field expressions where the left part is a multiline expression are not
85 ; indented by cargo fmt.
86 ; Because this multiline expression might be nested in an arbitrary number of
87 ; field expressions, this can only be matched using a Regex.
88 (field_expression
89 value: (_) @val
90 "." @outdent
91 ; Check whether the first line ends with `(`, `{` or `[` (up to whitespace).
92 (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
93 )
94 ; Same as above, but with an additional `call_expression`. This is required since otherwise
95 ; the arguments of the function call won't be outdented.
96 (call_expression
97 function: (field_expression
98 value: (_) @val
99 "." @outdent
100 (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
101 )
102 arguments: (_) @outdent
103 )
104
105 ; Indent if guards in patterns.
106 ; Since the tree-sitter grammar doesn't create a node for the if expression,
107 ; it's not possible to do this correctly in all cases. Indenting the tail of the
108 ; whole pattern whenever it contains an `if` only fails if the `if` appears after
109 ; the second line of the pattern (which should only rarely be the case)
110 (match_pattern
111 .
112 (_) @expr-start
113 "if" @pattern-guard
114 (#not-same-line? @expr-start @pattern-guard)
115 ) @indent
116
117 ; Align closure parameters if they span more than one line
118 (closure_parameters
119 "|"
120 .
121 (_) @anchor
122 (_) @expr-end
123 .
124 (#not-same-line? @anchor @expr-end)
125 ) @align
126
127 (for_expression
128 "in" @in
129 .
130 (_) @indent
131 (#not-same-line? @in @indent)
132
133 )