Skip to content

Commit cf78077

Browse files
committed
Fix spacing around angles
1 parent a2d31e8 commit cf78077

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

CodeGeneration/Sources/generate-swiftbasicformat/BasicFormatFile.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ let basicFormatFile = SourceFile {
122122
}
123123

124124
FunctionDecl("open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool") {
125+
SwitchStmt("""
126+
switch (token.tokenKind, token.previousToken(viewMode: .sourceAccurate)?.tokenKind) {
127+
case (.leftAngle, .identifier(_)),
128+
(.rightAngle, .identifier(_)),
129+
(.rightAngle, .postfixQuestionMark):
130+
return false
131+
default:
132+
break
133+
}
134+
""")
135+
125136
SwitchStmt(expression: Expr("token.tokenKind")) {
126137
for token in SYNTAX_TOKENS {
127138
if token.requiresLeadingSpace {
@@ -143,6 +154,8 @@ let basicFormatFile = SourceFile {
143154
(.asKeyword, .postfixQuestionMark),
144155
(.initKeyword, .leftParen),
145156
(.initKeyword, .postfixQuestionMark),
157+
(.leftAngle, .identifier(_)),
158+
(.rightAngle, .postfixQuestionMark),
146159
(.tryKeyword, .exclamationMark),
147160
(.tryKeyword, .postfixQuestionMark):
148161
return false

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ open class BasicFormat: SyntaxRewriter {
124124
}
125125

126126
open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool {
127+
switch (token.tokenKind, token.previousToken(viewMode: .sourceAccurate)?.tokenKind) {
128+
case (.leftAngle, .identifier(_ )),
129+
(.rightAngle, .identifier(_ )),
130+
(.rightAngle, .postfixQuestionMark):
131+
return false
132+
default:
133+
break
134+
}
127135
switch token.tokenKind {
128136
case .whereKeyword:
129137
return true
@@ -152,6 +160,8 @@ open class BasicFormat: SyntaxRewriter {
152160
(.asKeyword, .postfixQuestionMark),
153161
(.initKeyword, .leftParen),
154162
(.initKeyword, .postfixQuestionMark),
163+
(.leftAngle, .identifier(_ )),
164+
(.rightAngle, .postfixQuestionMark),
155165
(.tryKeyword, .exclamationMark),
156166
(.tryKeyword, .postfixQuestionMark):
157167
return false

Tests/SwiftSyntaxBuilderTest/StructTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ final class StructTests: XCTestCase {
6969
public struct TestStruct {
7070
/// A nested struct
7171
/// with multi line comment
72-
struct NestedStruct < A, B: C, D > where A: X, A.P == D {
72+
struct NestedStruct<A, B: C, D> where A: X, A.P == D {
7373
}
7474
/// A nested struct\r\
7575
/// with multi line comment where the newline is a CR\r\

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class VariableTests: XCTestCase {
2525
AssertBuildResult(buildable, "␣let a: [Int]")
2626
}
2727

28-
func testVariableDeclWithTry() {
28+
func testVariableDeclWithStringParsing() {
2929
let testCases: [UInt: (VariableDecl, String)] = [
3030
#line: (
3131
VariableDecl("let content = try? String(contentsOf: url)"),
@@ -35,6 +35,10 @@ final class VariableTests: XCTestCase {
3535
VariableDecl("let content = try! String(contentsOf: url)"),
3636
"let content = try! String(contentsOf: url)"
3737
),
38+
#line: (
39+
VariableDecl("var newLayout: ContiguousArray<RawSyntax?>?"),
40+
"var newLayout: ContiguousArray<RawSyntax?>?"
41+
),
3842
]
3943

4044
for (line, testCase) in testCases {

0 commit comments

Comments
 (0)