Skip to content

Commit c216877

Browse files
committed
Fix CodeGenerationFormat to correctly indent LabeledExprListSyntax in method calls that start on a new line
1 parent 51eb17a commit c216877

File tree

10 files changed

+561
-540
lines changed

10 files changed

+561
-540
lines changed

CodeGeneration/Sources/Utils/CodeGenerationFormat.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,27 @@ public class CodeGenerationFormat: BasicFormat {
9696
let children = node.children(viewMode: .all)
9797
// Short tuple element list literals are presented on one line, list each element on a different line.
9898
if children.count > maxElementsOnSameLine {
99+
let inMethodCallThatStartsOnNewline =
100+
if let functionCallExpr = node.parent?.as(FunctionCallExprSyntax.self),
101+
let memberAccessExpr = functionCallExpr.calledExpression.as(MemberAccessExprSyntax.self),
102+
memberAccessExpr.period.leadingTrivia.contains(where: \.isNewline)
103+
|| memberAccessExpr.period.previousToken(viewMode: .sourceAccurate)?.trailingTrivia.contains(
104+
where: \.isNewline
105+
) ?? false
106+
{
107+
true
108+
} else {
109+
false
110+
}
111+
if inMethodCallThatStartsOnNewline {
112+
increaseIndentationLevel()
113+
}
114+
defer {
115+
if inMethodCallThatStartsOnNewline {
116+
decreaseIndentationLevel()
117+
}
118+
}
119+
99120
return LabeledExprListSyntax(
100121
formatChildrenSeparatedByNewline(children: children, elementType: LabeledExprSyntax.self)
101122
)

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesAB.swift

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ public struct AccessorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclS
369369
}
370370
return Syntax(self)
371371
.replacingChild(
372-
at: 1,
373-
with: collection,
374-
rawNodeArena: arena,
375-
allocationArena: arena
376-
)
372+
at: 1,
373+
with: collection,
374+
rawNodeArena: arena,
375+
allocationArena: arena
376+
)
377377
.cast(AccessorDeclSyntax.self)
378378
}
379379

@@ -918,11 +918,11 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
918918
}
919919
return Syntax(self)
920920
.replacingChild(
921-
at: 1,
922-
with: collection,
923-
rawNodeArena: arena,
924-
allocationArena: arena
925-
)
921+
at: 1,
922+
with: collection,
923+
rawNodeArena: arena,
924+
allocationArena: arena
925+
)
926926
.cast(ActorDeclSyntax.self)
927927
}
928928

@@ -964,11 +964,11 @@ public struct ActorDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
964964
}
965965
return Syntax(self)
966966
.replacingChild(
967-
at: 3,
968-
with: collection,
969-
rawNodeArena: arena,
970-
allocationArena: arena
971-
)
967+
at: 3,
968+
with: collection,
969+
rawNodeArena: arena,
970+
allocationArena: arena
971+
)
972972
.cast(ActorDeclSyntax.self)
973973
}
974974

@@ -1362,11 +1362,11 @@ public struct ArrayExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSynt
13621362
}
13631363
return Syntax(self)
13641364
.replacingChild(
1365-
at: 3,
1366-
with: collection,
1367-
rawNodeArena: arena,
1368-
allocationArena: arena
1369-
)
1365+
at: 3,
1366+
with: collection,
1367+
rawNodeArena: arena,
1368+
allocationArena: arena
1369+
)
13701370
.cast(ArrayExprSyntax.self)
13711371
}
13721372

@@ -2095,11 +2095,11 @@ public struct AssociatedTypeDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _Lea
20952095
}
20962096
return Syntax(self)
20972097
.replacingChild(
2098-
at: 1,
2099-
with: collection,
2100-
rawNodeArena: arena,
2101-
allocationArena: arena
2102-
)
2098+
at: 1,
2099+
with: collection,
2100+
rawNodeArena: arena,
2101+
allocationArena: arena
2102+
)
21032103
.cast(AssociatedTypeDeclSyntax.self)
21042104
}
21052105

@@ -2141,11 +2141,11 @@ public struct AssociatedTypeDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _Lea
21412141
}
21422142
return Syntax(self)
21432143
.replacingChild(
2144-
at: 3,
2145-
with: collection,
2146-
rawNodeArena: arena,
2147-
allocationArena: arena
2148-
)
2144+
at: 3,
2145+
with: collection,
2146+
rawNodeArena: arena,
2147+
allocationArena: arena
2148+
)
21492149
.cast(AssociatedTypeDeclSyntax.self)
21502150
}
21512151

@@ -3264,11 +3264,11 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp
32643264
}
32653265
return Syntax(self)
32663266
.replacingChild(
3267-
at: 1,
3268-
with: collection,
3269-
rawNodeArena: arena,
3270-
allocationArena: arena
3271-
)
3267+
at: 1,
3268+
with: collection,
3269+
rawNodeArena: arena,
3270+
allocationArena: arena
3271+
)
32723272
.cast(AttributedTypeSyntax.self)
32733273
}
32743274

@@ -3310,11 +3310,11 @@ public struct AttributedTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTyp
33103310
}
33113311
return Syntax(self)
33123312
.replacingChild(
3313-
at: 3,
3314-
with: collection,
3315-
rawNodeArena: arena,
3316-
allocationArena: arena
3317-
)
3313+
at: 3,
3314+
with: collection,
3315+
rawNodeArena: arena,
3316+
allocationArena: arena
3317+
)
33183318
.cast(AttributedTypeSyntax.self)
33193319
}
33203320

@@ -3750,11 +3750,11 @@ public struct AvailabilityConditionSyntax: SyntaxProtocol, SyntaxHashable, _Leaf
37503750
}
37513751
return Syntax(self)
37523752
.replacingChild(
3753-
at: 5,
3754-
with: collection,
3755-
rawNodeArena: arena,
3756-
allocationArena: arena
3757-
)
3753+
at: 5,
3754+
with: collection,
3755+
rawNodeArena: arena,
3756+
allocationArena: arena
3757+
)
37583758
.cast(AvailabilityConditionSyntax.self)
37593759
}
37603760

@@ -4309,11 +4309,11 @@ public struct BackDeployedAttributeArgumentsSyntax: SyntaxProtocol, SyntaxHashab
43094309
}
43104310
return Syntax(self)
43114311
.replacingChild(
4312-
at: 5,
4313-
with: collection,
4314-
rawNodeArena: arena,
4315-
allocationArena: arena
4316-
)
4312+
at: 5,
4313+
with: collection,
4314+
rawNodeArena: arena,
4315+
allocationArena: arena
4316+
)
43174317
.cast(BackDeployedAttributeArgumentsSyntax.self)
43184318
}
43194319

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,11 @@ public struct CatchClauseSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNode
516516
}
517517
return Syntax(self)
518518
.replacingChild(
519-
at: 3,
520-
with: collection,
521-
rawNodeArena: arena,
522-
allocationArena: arena
523-
)
519+
at: 3,
520+
with: collection,
521+
rawNodeArena: arena,
522+
allocationArena: arena
523+
)
524524
.cast(CatchClauseSyntax.self)
525525
}
526526

@@ -872,11 +872,11 @@ public struct ClassDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
872872
}
873873
return Syntax(self)
874874
.replacingChild(
875-
at: 1,
876-
with: collection,
877-
rawNodeArena: arena,
878-
allocationArena: arena
879-
)
875+
at: 1,
876+
with: collection,
877+
rawNodeArena: arena,
878+
allocationArena: arena
879+
)
880880
.cast(ClassDeclSyntax.self)
881881
}
882882

@@ -918,11 +918,11 @@ public struct ClassDeclSyntax: DeclSyntaxProtocol, SyntaxHashable, _LeafDeclSynt
918918
}
919919
return Syntax(self)
920920
.replacingChild(
921-
at: 3,
922-
with: collection,
923-
rawNodeArena: arena,
924-
allocationArena: arena
925-
)
921+
at: 3,
922+
with: collection,
923+
rawNodeArena: arena,
924+
allocationArena: arena
925+
)
926926
.cast(ClassDeclSyntax.self)
927927
}
928928

@@ -1275,11 +1275,11 @@ public struct ClosureCaptureClauseSyntax: SyntaxProtocol, SyntaxHashable, _LeafS
12751275
}
12761276
return Syntax(self)
12771277
.replacingChild(
1278-
at: 3,
1279-
with: collection,
1280-
rawNodeArena: arena,
1281-
allocationArena: arena
1282-
)
1278+
at: 3,
1279+
with: collection,
1280+
rawNodeArena: arena,
1281+
allocationArena: arena
1282+
)
12831283
.cast(ClosureCaptureClauseSyntax.self)
12841284
}
12851285

@@ -1835,11 +1835,11 @@ public struct ClosureExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSy
18351835
}
18361836
return Syntax(self)
18371837
.replacingChild(
1838-
at: 5,
1839-
with: collection,
1840-
rawNodeArena: arena,
1841-
allocationArena: arena
1842-
)
1838+
at: 5,
1839+
with: collection,
1840+
rawNodeArena: arena,
1841+
allocationArena: arena
1842+
)
18431843
.cast(ClosureExprSyntax.self)
18441844
}
18451845

@@ -2016,11 +2016,11 @@ public struct ClosureParameterClauseSyntax: SyntaxProtocol, SyntaxHashable, _Lea
20162016
}
20172017
return Syntax(self)
20182018
.replacingChild(
2019-
at: 3,
2020-
with: collection,
2021-
rawNodeArena: arena,
2022-
allocationArena: arena
2023-
)
2019+
at: 3,
2020+
with: collection,
2021+
rawNodeArena: arena,
2022+
allocationArena: arena
2023+
)
20242024
.cast(ClosureParameterClauseSyntax.self)
20252025
}
20262026

@@ -2211,11 +2211,11 @@ public struct ClosureParameterSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta
22112211
}
22122212
return Syntax(self)
22132213
.replacingChild(
2214-
at: 1,
2215-
with: collection,
2216-
rawNodeArena: arena,
2217-
allocationArena: arena
2218-
)
2214+
at: 1,
2215+
with: collection,
2216+
rawNodeArena: arena,
2217+
allocationArena: arena
2218+
)
22192219
.cast(ClosureParameterSyntax.self)
22202220
}
22212221

@@ -2256,11 +2256,11 @@ public struct ClosureParameterSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta
22562256
}
22572257
return Syntax(self)
22582258
.replacingChild(
2259-
at: 3,
2260-
with: collection,
2261-
rawNodeArena: arena,
2262-
allocationArena: arena
2263-
)
2259+
at: 3,
2260+
with: collection,
2261+
rawNodeArena: arena,
2262+
allocationArena: arena
2263+
)
22642264
.cast(ClosureParameterSyntax.self)
22652265
}
22662266

@@ -2757,11 +2757,11 @@ public struct ClosureSignatureSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta
27572757
}
27582758
return Syntax(self)
27592759
.replacingChild(
2760-
at: 1,
2761-
with: collection,
2762-
rawNodeArena: arena,
2763-
allocationArena: arena
2764-
)
2760+
at: 1,
2761+
with: collection,
2762+
rawNodeArena: arena,
2763+
allocationArena: arena
2764+
)
27652765
.cast(ClosureSignatureSyntax.self)
27662766
}
27672767

@@ -3258,11 +3258,11 @@ public struct CodeBlockSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodePr
32583258
}
32593259
return Syntax(self)
32603260
.replacingChild(
3261-
at: 3,
3262-
with: collection,
3263-
rawNodeArena: arena,
3264-
allocationArena: arena
3265-
)
3261+
at: 3,
3262+
with: collection,
3263+
rawNodeArena: arena,
3264+
allocationArena: arena
3265+
)
32663266
.cast(CodeBlockSyntax.self)
32673267
}
32683268

@@ -3499,11 +3499,11 @@ public struct CompositionTypeSyntax: TypeSyntaxProtocol, SyntaxHashable, _LeafTy
34993499
}
35003500
return Syntax(self)
35013501
.replacingChild(
3502-
at: 1,
3503-
with: collection,
3504-
rawNodeArena: arena,
3505-
allocationArena: arena
3506-
)
3502+
at: 1,
3503+
with: collection,
3504+
rawNodeArena: arena,
3505+
allocationArena: arena
3506+
)
35073507
.cast(CompositionTypeSyntax.self)
35083508
}
35093509

0 commit comments

Comments
 (0)