@@ -162,7 +162,9 @@ fn format_node(
162162 SyntaxKind :: MemberAccess => {
163163 return format_member_access ( node, writer, state) ;
164164 }
165-
165+ SyntaxKind :: Predicate => {
166+ return format_predicate ( node, writer, state) ;
167+ }
166168 _ => ( ) ,
167169 }
168170
@@ -1320,6 +1322,26 @@ fn format_member_access(
13201322 Ok ( ( ) )
13211323}
13221324
1325+ fn format_predicate (
1326+ node : & SyntaxNode ,
1327+ writer : & mut impl TokenWriter ,
1328+ state : & mut FormatState ,
1329+ ) -> Result < ( ) , std:: io:: Error > {
1330+ for s in node. children_with_tokens ( ) {
1331+ state. skip_all_whitespace = true ;
1332+ match s. kind ( ) {
1333+ SyntaxKind :: FatArrow => {
1334+ state. insert_whitespace ( " " ) ;
1335+ fold ( s, writer, state) ?;
1336+ state. insert_whitespace ( " " ) ;
1337+ }
1338+ _ => fold ( s, writer, state) ?,
1339+ }
1340+ }
1341+
1342+ Ok ( ( ) )
1343+ }
1344+
13231345#[ cfg( test) ]
13241346mod tests {
13251347 use super :: * ;
@@ -2189,6 +2211,34 @@ export component MainWindow2 inherits Rectangle {
21892211 let bar: int = 42;
21902212 }
21912213}
2214+ "# ,
2215+ ) ;
2216+ }
2217+
2218+ #[ test]
2219+ fn predicate ( ) {
2220+ assert_formatting (
2221+ "component X { property <[int]> arr: [1, 2, 3, 4, 5]; function foo() { arr.any(x\n => x == 1 ); } }" ,
2222+ r#"component X {
2223+ property <[int]> arr: [1, 2, 3, 4, 5];
2224+ function foo() {
2225+ arr.any(x => x == 1);
2226+ }
2227+ }
2228+ "# ,
2229+ ) ;
2230+ }
2231+
2232+ #[ test]
2233+ fn nested_predicate ( ) {
2234+ assert_formatting (
2235+ "component X { property <[[int]]> arr: [[1, 2, 3, 4, 5]]; function foo() { arr.any(x => x.all(y => y == 7 ) ); } }" ,
2236+ r#"component X {
2237+ property <[[int]]> arr: [[1, 2, 3, 4, 5]];
2238+ function foo() {
2239+ arr.any(x => x.all(y => y == 7));
2240+ }
2241+ }
21922242"# ,
21932243 ) ;
21942244 }
0 commit comments