Debian Codegraph @

runtime/queries/rust/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 (await_expression)
18 (tuple_expression)
19 (array_expression)
20 (where_clause)
21 (type_cast_expression)
22
23 (token_tree)
24 (macro_definition)
25 (token_tree_pattern)
26 (token_repetition)
27 ] @indent
28
29 [
30 "}"
31 "]"
32 ")"
33 ] @outdent
34
35 ; Indent the right side of assignments.
36 ; The #not-same-line? predicate is required to prevent an extra indent for e.g.
37 ; an else-clause where the previous if-clause starts on the same line as the assignment.
38 (assignment_expression
39 .
40 (_) @expr-start
41 right: (_) @indent
42 (#not-same-line? @indent @expr-start)
43
44 )
45 (compound_assignment_expr
46 .
47 (_) @expr-start
48 right: (_) @indent
49 (#not-same-line? @indent @expr-start)
50
51 )
52 (let_declaration
53 "let" @expr-start
54 value: (_) @indent
55 alternative: (_)? @indent
56 (#not-same-line? @indent @expr-start)
57
58 )
59 (let_condition
60 .
61 (_) @expr-start
62 value: (_) @indent
63 (#not-same-line? @indent @expr-start)
64
65 )
66 (if_expression
67 .
68 (_) @expr-start
69 condition: (_) @indent
70 (#not-same-line? @indent @expr-start)
71
72 )
73 (static_item
74 .
75 (_) @expr-start
76 value: (_) @indent
77 (#not-same-line? @indent @expr-start)
78
79 )
80 (field_pattern
81 .
82 (_) @expr-start
83 pattern: (_) @indent
84 (#not-same-line? @indent @expr-start)
85
86 )
87 ; Indent type aliases that span multiple lines, similar to
88 ; regular assignment expressions
89 (type_item
90 .
91 (_) @expr-start
92 type: (_) @indent
93 (#not-same-line? @indent @expr-start)
94
95 )
96
97 ; Some field expressions where the left part is a multiline expression are not
98 ; indented by cargo fmt.
99 ; Because this multiline expression might be nested in an arbitrary number of
100 ; field expressions, this can only be matched using a Regex.
101 (field_expression
102 value: (_) @val
103 "." @outdent
104 ; Check whether the first line ends with `(`, `{` or `[` (up to whitespace).
105 (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
106 )
107 ; Same as above, but with an additional `call_expression`. This is required since otherwise
108 ; the arguments of the function call won't be outdented.
109 (call_expression
110 function: (field_expression
111 value: (_) @val
112 "." @outdent
113 (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
114 )
115 arguments: (_) @outdent
116 )
117 ; Same again for `.await` off a multiline receiver, so it lines up with the
118 ; other links in the chain instead of indenting a level deeper.
119 (await_expression
120 (_) @val
121 "." @outdent
122 (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
123 )
124
125 ; Indent if guards in patterns.
126 ; Since the tree-sitter grammar doesn't create a node for the if expression,
127 ; it's not possible to do this correctly in all cases. Indenting the tail of the
128 ; whole pattern whenever it contains an `if` only fails if the `if` appears after
129 ; the second line of the pattern (which should only rarely be the case)
130 (match_pattern
131 .
132 (_) @expr-start
133 "if" @pattern-guard
134 (#not-same-line? @expr-start @pattern-guard)
135 ) @indent
136
137 ; Align closure parameters if they span more than one line
138 (closure_parameters
139 "|"
140 .
141 (_) @anchor
142 (_) @expr-end
143 .
144 (#not-same-line? @anchor @expr-end)
145 ) @align
146
147 (for_expression
148 "in" @in
149 .
150 (_) @indent
151 (#not-same-line? @in @indent)
152
153 )
154
155 ; Multi-line string / raw-string bodies are literal content: preserve them.
156 [
157 (string_literal)
158 (raw_string_literal)
159 ] @opaque