@@ -232,6 +232,10 @@ class FormatContext {
232
232
return LineAndColumn;
233
233
}
234
234
235
+ bool exprEndAtLine (Expr *E, unsigned Line) {
236
+ return E->getEndLoc ().isValid () && SM.getLineNumber (E->getEndLoc ()) == Line;
237
+ };
238
+
235
239
bool shouldAddIndentForLine (unsigned Line) {
236
240
if (Cursor == Stack.rend ())
237
241
return false ;
@@ -399,16 +403,29 @@ class FormatContext {
399
403
// Character(UnicodeScalar(c))
400
404
// }) <--- No indentation here.
401
405
auto AtCursorExpr = Cursor->getAsExpr ();
402
- if (AtCursorExpr && (isa<ParenExpr>(AtCursorExpr) ||
403
- isa<TupleExpr>(AtCursorExpr))) {
404
- if (AtExprEnd && isa<CallExpr>(AtExprEnd)) {
405
- if (AtExprEnd->getEndLoc ().isValid () &&
406
- AtCursorExpr->getEndLoc ().isValid () &&
407
- Line == SM.getLineNumber (AtExprEnd->getEndLoc ()) &&
408
- Line == SM.getLineNumber (AtCursorExpr->getEndLoc ())) {
406
+ if (AtExprEnd && AtCursorExpr && (isa<ParenExpr>(AtCursorExpr) ||
407
+ isa<TupleExpr>(AtCursorExpr))) {
408
+ if (isa<CallExpr>(AtExprEnd)) {
409
+ if (exprEndAtLine (AtExprEnd, Line) &&
410
+ exprEndAtLine (AtCursorExpr, Line)) {
409
411
return false ;
410
412
}
411
413
}
414
+
415
+ // foo(A: {
416
+ // ...
417
+ // }, B: { <--- No indentation here.
418
+ // ...
419
+ // })
420
+ if (auto *TE = dyn_cast<TupleExpr>(AtCursorExpr)) {
421
+ if (isa<ClosureExpr>(AtExprEnd) && exprEndAtLine (AtExprEnd, Line)) {
422
+ for (auto *ELE : TE->getElements ()) {
423
+ if (exprEndAtLine (ELE, Line)) {
424
+ return false ;
425
+ }
426
+ }
427
+ }
428
+ }
412
429
}
413
430
414
431
// Indent another level from the outer context by default.
0 commit comments