Skip to content

Commit b665b8e

Browse files
committed
Supported Comments in SourceFile
1 parent bc6c721 commit b665b8e

File tree

2 files changed

+816
-1602
lines changed

2 files changed

+816
-1602
lines changed

Sources/SwiftSyntaxBuilder/BuildableNodes.swift.gyb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@ public struct ${type.buildable()}: ${base_type.buildable()}, ${type.expressible_
107107

108108
/// Conformance to `${base_type.buildable()}`.
109109
public func build${base_type.base_name()}(format: Format, leadingTrivia: Trivia? = nil) -> ${base_type.syntax()} {
110+
% if type.buildable() != 'SourceFile':
110111
let result = build${type.base_name()}(format: format, leadingTrivia: leadingTrivia)
111-
112-
113-
if let itemLeadingTrivia = itemLeadingTrivia
114-
{
115-
let formattedLeadingTrivia = [itemLeadingTrivia, format._makeIndent()].reduce(.zero, +)
116-
return ${base_type.syntax()}(result).withLeadingTrivia(formattedLeadingTrivia)
117-
}
118-
112+
% end
113+
% if type.buildable() == 'SourceFile':
114+
let combinedTrivia = [format._makeIndent(),
115+
leadingTrivia,
116+
itemLeadingTrivia]
117+
.compactMap { $0 }
118+
.reduce(.zero, +)
119+
% if type.buildable() == 'SourceFile':
120+
let result = buildSourceFile(format: format, leadingTrivia: combinedTrivia)
121+
% end
122+
% else:
123+
if let itemLeadingTrivia = itemLeadingTrivia {
124+
let formattedLeadingTrivia = [itemLeadingTrivia, format._makeIndent()].reduce(.zero, +)
125+
return ${base_type.syntax()}(result).withLeadingTrivia(formattedLeadingTrivia)
126+
}
127+
% end
119128
return ${base_type.syntax()}(result)
120129
}
121130

0 commit comments

Comments
 (0)