Skip to content

Commit 1e06a49

Browse files
committed
When formatting, insert a trailing space after 'async'
1 parent 7957b5e commit 1e06a49

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

CodeGeneration/Sources/generate-swiftbasicformat/BasicFormatFile.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private func createTokenFormatFunction() -> FunctionDecl {
168168
) {
169169
VariableDecl("var node = node")
170170
SwitchStmt(expression: MemberAccessExpr(base: "node", name: "tokenKind")) {
171-
for token in SYNTAX_TOKENS {
171+
for token in SYNTAX_TOKENS where token.name != "ContextualKeyword" {
172172
SwitchCase(label: SwitchCaseLabel(caseItems: CaseItem(pattern: ExpressionPattern(expression: MemberAccessExpr(name: token.swiftKind))))) {
173173
if token.requiresLeadingSpace {
174174
IfStmt(
@@ -196,6 +196,20 @@ private func createTokenFormatFunction() -> FunctionDecl {
196196
SwitchCase(label: SwitchCaseLabel(caseItems: CaseItem(pattern: ExpressionPattern(expression: MemberAccessExpr(name: "eof"))))) {
197197
BreakStmt("break")
198198
}
199+
SwitchCase(label: SwitchCaseLabel(caseItems: CaseItem(pattern: ExpressionPattern(expression: MemberAccessExpr(name: "contextualKeyword"))))) {
200+
SwitchStmt(
201+
"""
202+
switch node.text {
203+
case "async":
204+
if node.trailingTrivia.isEmpty {
205+
node.trailingTrivia += .space
206+
}
207+
default:
208+
break
209+
}
210+
"""
211+
)
212+
}
199213
}
200214
SequenceExpr("node.leadingTrivia = node.leadingTrivia.indented(indentation: indentation)")
201215
SequenceExpr("node.trailingTrivia = node.trailingTrivia.indented(indentation: indentation)")

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,8 +3147,6 @@ open class BasicFormat: SyntaxRewriter {
31473147
break
31483148
case .dollarIdentifier:
31493149
break
3150-
case .contextualKeyword:
3151-
break
31523150
case .rawStringDelimiter:
31533151
break
31543152
case .stringSegment:
@@ -3159,6 +3157,15 @@ open class BasicFormat: SyntaxRewriter {
31593157
break
31603158
case .eof:
31613159
break
3160+
case .contextualKeyword:
3161+
switch node.text {
3162+
case "async":
3163+
if node.trailingTrivia.isEmpty {
3164+
node.trailingTrivia += .space
3165+
}
3166+
default:
3167+
break
3168+
}
31623169
}
31633170
node.leadingTrivia = node.leadingTrivia.indented(indentation: indentation)
31643171
node.trailingTrivia = node.trailingTrivia.indented(indentation: indentation)

0 commit comments

Comments
 (0)