Skip to content

Commit ff99d65

Browse files
author
Nathan Hawes
authored
Merge pull request #32582 from nathawes/array-literal-sub-expr-indentation-fix
[SourceKit/CodeFormat] Fix multi-line array literal elements not indenting relative to their first line.
2 parents 4d3bd22 + f245717 commit ff99d65

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/IDE/Formatting.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,8 +2342,17 @@ class FormatWalker : public ASTWalker {
23422342
return None;
23432343

23442344
ListAligner Aligner(SM, TargetLocation, L, L, R, true);
2345-
for (auto *Elem: AE->getElements())
2346-
Aligner.updateAlignment(Elem->getStartLoc(), Elem->getEndLoc(), Elem);
2345+
for (auto *Elem: AE->getElements()) {
2346+
SourceRange ElemRange = Elem->getSourceRange();
2347+
Aligner.updateAlignment(ElemRange, Elem);
2348+
if (isTargetContext(ElemRange)) {
2349+
Aligner.setAlignmentIfNeeded(CtxOverride);
2350+
return IndentContext {
2351+
ElemRange.Start,
2352+
!OutdentChecker::hasOutdent(SM, ElemRange, Elem)
2353+
};
2354+
}
2355+
}
23472356
return Aligner.getContextAndSetAlignment(CtxOverride);
23482357
}
23492358

test/swift-indent/basic.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,3 +1052,14 @@ struct <#name#> {
10521052
<#fields#>
10531053
func foo() {}
10541054
}
1055+
1056+
1057+
// Array literal elements should have their continuation lines indented relative to their first line.
1058+
1059+
doStuffWithList([
1060+
baseThing()
1061+
.map { $0 }
1062+
.append(\.sdfsdf),
1063+
secondItem
1064+
.filter {$0 < 10}
1065+
])

0 commit comments

Comments
 (0)