@@ -14,9 +14,11 @@
14 (call_expression)
14 (call_expression)
15 (binary_expression)
15 (binary_expression)
16 (field_expression)
16 (field_expression)
17 (tuple_expression)
18 (tuple_expression)
18 (array_expression)
19 (array_expression)
19 (where_clause)
20 (where_clause)
21+ (type_cast_expression)
21 (token_tree)
23 (token_tree)
22 (macro_definition)
24 (macro_definition)
@@ -48,10 +50,16 @@
48 (#set! "scope" "all")
50 (#set! "scope" "all")
50(let_declaration
52(let_declaration
55+ alternative: (_)? @indent
56+ (#not-same-line? @indent @expr-start)
57+ (#set! "scope" "all")
52 (_) @expr-start
61 (_) @expr-start
53 value: (_) @indent
62 value: (_) @indent
54− alternative: (_)? @indent
55 (#not-same-line? @indent @expr-start)
63 (#not-same-line? @indent @expr-start)
56 (#set! "scope" "all")
64 (#set! "scope" "all")
@@ -69,6 +77,22 @@
69 (#not-same-line? @indent @expr-start)
77 (#not-same-line? @indent @expr-start)
70 (#set! "scope" "all")
78 (#set! "scope" "all")
84+ (#not-same-line? @indent @expr-start)
85+ (#set! "scope" "all")
87+; Indent type aliases that span multiple lines, similar to
88+; regular assignment expressions
93+ (#not-same-line? @indent @expr-start)
94+ (#set! "scope" "all")
73; Some field expressions where the left part is a multiline expression are not
97; Some field expressions where the left part is a multiline expression are not
74; indented by cargo fmt.
98; indented by cargo fmt.
@@ -77,5 +101,48 @@
77(field_expression
101(field_expression
78 value: (_) @val
102 value: (_) @val
79 "." @outdent
103 "." @outdent
104+ ; Check whether the first line ends with `(`, `{` or `[` (up to whitespace).
80− (#match? @val "(\\A[^\\n\\r]+\\([\\t ]*(\\n|\\r).*)|(\\A[^\\n\\r]*\\{[\\t ]*(\\n|\\r))")
105+ (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
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.
110+ function: (field_expression
113+ (#match? @val "(\\A[^\\n\\r]+(\\(|\\{|\\[)[\\t ]*(\\n|\\r))")
115+ arguments: (_) @outdent
119+; Indent if guards in patterns.
120+; Since the tree-sitter grammar doesn't create a node for the if expression,
121+; it's not possible to do this correctly in all cases. Indenting the tail of the
122+; whole pattern whenever it contains an `if` only fails if the `if` appears after
123+; the second line of the pattern (which should only rarely be the case)
128+ (#not-same-line? @expr-start @pattern-guard)
131+; Align closure parameters if they span more than one line
138+ (#not-same-line? @anchor @expr-end)
145+ (#not-same-line? @in @indent)
146+ (#set! "scope" "all")