Skip to content

Commit 54e742b

Browse files
committed
Allow trivia to be added to SyntaxStringInterpolation without adding a raw: label
`Trivia` is a first-class citizen in SwiftSyntax and you shouldn’t need to add `raw` in front of it to add it t`SyntaxStringInterpolation`.
1 parent e340af4 commit 54e742b

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxBaseNodesFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
5454

5555
try! StructDeclSyntax(
5656
"""
57-
\(raw: node.documentation)
57+
\(node.documentation)
5858
public struct \(node.kind.syntaxType): \(node.kind.protocolType), SyntaxHashable
5959
"""
6060
) {

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxCollectionsFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3232

3333
try! StructDeclSyntax(
3434
"""
35-
\(raw: documentation)
35+
\(documentation)
3636
public struct \(node.kind.syntaxType): SyntaxCollection, SyntaxHashable
3737
"""
3838
) {

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
3939
"""
4040
// MARK: - \(raw: node.kind.syntaxType)
4141
42-
\(raw: documentation)
42+
\(documentation)
4343
public struct \(raw: node.kind.syntaxType): \(raw: node.baseType.syntaxBaseName)Protocol, SyntaxHashable
4444
"""
4545
) {
@@ -78,7 +78,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
7878

7979
try! InitializerDeclSyntax(
8080
"""
81-
\(raw: node.generateInitializerDocComment())
81+
\(node.generateInitializerDocComment())
8282
\(node.generateInitializerDeclHeader())
8383
"""
8484
) {
@@ -163,7 +163,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
163163

164164
try! VariableDeclSyntax(
165165
"""
166-
\(raw: child.documentation)
166+
\(child.documentation)
167167
public var \(child.varOrCaseName.backtickedIfNeeded): \(type)
168168
"""
169169
) {

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxTraitsFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ let syntaxTraitsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
2121
"""
2222
// MARK: - \(trait.protocolName)
2323
24-
\(raw: trait.documentation)
24+
\(trait.documentation)
2525
public protocol \(trait.protocolName): SyntaxProtocol
2626
"""
2727
) {
2828
for child in trait.children {
2929
DeclSyntax(
3030
"""
31-
\(raw: child.documentation)
31+
\(child.documentation)
3232
var \(child.varOrCaseName): \(child.syntaxNodeKind.syntaxType)\(raw: child.isOptional ? "?" : "") { get set }
3333
"""
3434
)

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntaxbuilder/BuildableCollectionNodesFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let buildableCollectionNodesFile = SourceFileSyntax(leadingTrivia: copyrightHead
2929
// Generate collection node struct
3030
try! ExtensionDeclSyntax(
3131
"""
32-
\(raw: docComment)
32+
\(docComment)
3333
extension \(raw: node.type.syntaxBaseName): ExpressibleByArrayLiteral
3434
"""
3535
) {

Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ extension SyntaxStringInterpolation: StringInterpolationProtocol {
104104
self.appendInterpolation(buildable.formatted(using: format))
105105
}
106106

107+
public mutating func appendInterpolation(
108+
_ trivia: Trivia
109+
) {
110+
self.appendInterpolation(raw: trivia.description)
111+
}
112+
107113
/// Interpolates a literal or similar expression syntax equivalent to `value`.
108114
///
109115
/// - SeeAlso: ``SwiftSyntax/ExprSyntax/init(literal:)``

0 commit comments

Comments
 (0)