Skip to content

Commit 7307beb

Browse files
committed
Support generic parameter wrapping.
1 parent 760ce43 commit 7307beb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Sources/PrettyPrint/TokenStreamCreator.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
282282
}
283283

284284
override func visit(_ node: GenericParameterClauseSyntax) {
285-
after(node.leftAngleBracket, tokens: .open(.consistent, 2), .break(size: 0))
286-
before(node.rightAngleBracket, tokens: .break(size: 0), .close)
285+
after(node.leftAngleBracket, tokens: .break(size: 0, offset: 2), .open(.consistent, 0))
286+
before(node.rightAngleBracket, tokens: .break(size: 0, offset: -2), .close)
287287
super.visit(node)
288288
}
289289

@@ -663,7 +663,9 @@ private final class TokenStreamCreator: SyntaxVisitor {
663663
}
664664

665665
override func visit(_ node: GenericParameterSyntax) {
666+
before(node.firstToken, tokens: .open)
666667
after(node.colon, tokens: .break)
668+
after(node.lastToken, tokens: .close)
667669
super.visit(node)
668670
}
669671

Tests/PrettyPrinterTests/FunctionDeclTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public class FunctionDeclTests: PrettyPrintTestCase {
6767
func myFun<S, T>(var1: S, var2: T) {
6868
print("Hello World")
6969
}
70+
71+
func longerNameFun<ReallyLongTypeName: Conform, TypeName>(var1: ReallyLongTypeNAme, var2: TypeName) {
72+
let a = 123
73+
}
7074
"""
7175

7276
let expected =
@@ -75,6 +79,16 @@ public class FunctionDeclTests: PrettyPrintTestCase {
7579
print("Hello World")
7680
}
7781
82+
func longerNameFun<
83+
ReallyLongTypeName: Conform,
84+
TypeName
85+
>(
86+
var1: ReallyLongTypeNAme,
87+
var2: TypeName
88+
) {
89+
let a = 123
90+
}
91+
7892
"""
7993

8094
assertPrettyPrintEqual(input: input, expected: expected, linelength: 40)

0 commit comments

Comments
 (0)