@@ -14,9 +14,11 @@
1414 (call_expression)
1515 (binary_expression)
1616 (field_expression)
17+ (await_expression)
1718 (tuple_expression)
1819 (array_expression)
1920 (where_clause)
21+ (type_cast_expression)
2022
2123 (token_tree)
2224 (macro_definition)
@@ -48,10 +50,16 @@
4850 (#set! "scope" "all")
4951)
5052(let_declaration
53+ "let" @expr-start
54+ value: (_) @indent
55+ alternative: (_)? @indent
56+ (#not-same-line? @indent @expr-start)
57+ (#set! "scope" "all")
58+)
59+(let_condition
5160 .
5261 (_) @expr-start
5362 value: (_) @indent
54− alternative: (_)? @indent
5563 (#not-same-line? @indent @expr-start)
5664 (#set! "scope" "all")
5765)
@@ -69,6 +77,22 @@
6977 (#not-same-line? @indent @expr-start)
7078 (#set! "scope" "all")
7179)
80+(field_pattern
81+ .
82+ (_) @expr-start
83+ pattern: (_) @indent
84+ (#not-same-line? @indent @expr-start)
85+ (#set! "scope" "all")
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+ (#set! "scope" "all")
95+)
7296
7397; Some field expressions where the left part is a multiline expression are not
7498; indented by cargo fmt.
@@ -77,5 +101,48 @@
77101(field_expression
78102 value: (_) @val
79103 "." @outdent
80− (#match? @val "(\\A[^\\n\\r]+\\([\\t ]*(\\n|\\r).*)|(\\A[^\\n\\r]*\\{[\\t ]*(\\n|\\r))")
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+
118+
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)
124+(match_pattern
125+ .
126+ (_) @expr-start
127+ "if" @pattern-guard
128+ (#not-same-line? @expr-start @pattern-guard)
129+) @indent
130+
131+; Align closure parameters if they span more than one line
132+(closure_parameters
133+ "|"
134+ .
135+ (_) @anchor
136+ (_) @expr-end
137+ .
138+ (#not-same-line? @anchor @expr-end)
139+) @align
140+
141+(for_expression
142+ "in" @in
143+ .
144+ (_) @indent
145+ (#not-same-line? @in @indent)
146+ (#set! "scope" "all")
81147)
148+