@@ -232,6 +232,10 @@ class FormatContext {
232232 return LineAndColumn;
233233 }
234234
235+ bool exprEndAtLine (Expr *E, unsigned Line) {
236+ return E->getEndLoc ().isValid () && SM.getLineNumber (E->getEndLoc ()) == Line;
237+ };
238+
235239 bool shouldAddIndentForLine (unsigned Line) {
236240 if (Cursor == Stack.rend ())
237241 return false ;
@@ -399,16 +403,29 @@ class FormatContext {
399403 // Character(UnicodeScalar(c))
400404 // }) <--- No indentation here.
401405 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)) {
409411 return false ;
410412 }
411413 }
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+ }
412429 }
413430
414431 // Indent another level from the outer context by default.
0 commit comments