@@ -31,6 +31,7 @@ public struct ${type.buildable()}: ${base_type.buildable()}, ${type.expressible_
31
31
% for child in children:
32
32
let ${ child. name ( ) } : ${ child. type( ) . buildable( ) }
33
33
% end
34
+ public var itemLeadingTrivia : Trivia ?
34
35
35
36
/// Creates a `${type.buildable()}` using the provided parameters.
36
37
/// - Parameters:
@@ -107,7 +108,7 @@ public struct ${type.buildable()}: ${base_type.buildable()}, ${type.expressible_
107
108
/// Conformance to `${base_type.buildable()}`.
108
109
public func build${ base_type. base_name ( ) } ( format: Format, leadingTrivia: Trivia? = nil ) - > ${ base_type. syntax ( ) } {
109
110
let result = build ${ type. base_name ( ) } ( format: format, leadingTrivia: leadingTrivia)
110
- return ${ base_type. syntax ( ) } ( result)
111
+ return ${ base_type. syntax ( ) } ( result) . withLeadingTrivia ( itemLeadingTrivia ?? . zero )
111
112
}
112
113
113
114
/// Conformance to `${type.expressible_as()}`.
@@ -130,5 +131,24 @@ public struct ${type.buildable()}: ${base_type.buildable()}, ${type.expressible_
130
131
return self
131
132
}
132
133
% end
134
+
135
+ public func withDocBlokComment( _ text: String) - > Self {
136
+ let piece = TriviaPiece . docBlockComment ( " /** \(text) */" )
137
+ return addCommentPiece ( commentPiece: piece)
138
+ }
139
+
140
+ public func withLineComment( _ text: String) - > Self {
141
+ let piece = TriviaPiece . lineComment ( " // \( text) " )
142
+ return addCommentPiece ( commentPiece: piece)
143
+ }
144
+
145
+ private func addCommentPiece( commentPiece: TriviaPiece) - > Self {
146
+ var newSelf = self
147
+ newSelf. itemLeadingTrivia = itemLeadingTrivia?
148
+ . appending ( commentPiece)
149
+ . appending ( . newlines( 1 ) ) ?? [ commentPiece, . newlines( 1 ) ]
150
+ return newSelf
151
+ }
152
+
133
153
}
134
154
% end
0 commit comments