Skip to content

Commit 17271eb

Browse files
authored
Merge pull request #277 from kimdv/kimdv/add-documentation-buildables
Add documentation to buildables
2 parents bc6eefb + a625de2 commit 17271eb

File tree

2 files changed

+379
-1
lines changed

2 files changed

+379
-1
lines changed

Sources/SwiftSyntaxBuilder/Buildables.swift.gyb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public protocol ${kind}ListBuildable {
4343
% else:
4444
public protocol ${kind}ListBuildable: SyntaxListBuildable {
4545
% end
46+
/// Builds list of `${build_kind}`s.
47+
/// - Parameter format: The `Format` to use.
48+
/// - Parameter leadingTrivia: Replaces the the last leading trivia if not nil.
49+
/// - Returns: A list of `${build_kind}`.
4650
func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]
4751
}
4852

@@ -51,24 +55,40 @@ public protocol ${kind}Buildable: ${kind}ListBuildable {
5155
% else:
5256
public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {
5357
% end
58+
/// Builds a `${build_kind}`.
59+
/// - Parameter format: The `Format` to use.
60+
/// - Parameter leadingTrivia: Replaces the the last leading trivia if not nil.
61+
/// - Returns: A list of `${build_kind}`.
5462
func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}
5563
}
5664

5765
extension ${kind}Buildable {
5866
% if kind != 'Syntax':
67+
/// Builds a `${build_kind}`.
68+
/// - Returns: A `${build_kind}`.
5969
func build${kind}(format: Format) -> ${build_kind} {
6070
build${kind}(format: format, leadingTrivia: nil)
6171
}
6272

6373
% end
74+
/// Builds a `${build_kind}`.
75+
/// - Returns: A `${build_kind}`.
6476
public func buildSyntax(format: Format) -> Syntax {
6577
buildSyntax(format: format, leadingTrivia: nil)
6678
}
6779

80+
/// Builds a `${build_kind}`.
81+
/// - Parameter format: The `Format` to use.
82+
/// - Parameter leadingTrivia: Replaces the the last leading trivia if not nil.
83+
/// - Returns: A new `Syntax` with the builded `${build_kind}`.
6884
public func buildSyntax(format: Format, leadingTrivia: Trivia?) -> Syntax {
6985
Syntax(build${kind}(format: format, leadingTrivia: leadingTrivia))
7086
}
7187

88+
/// Builds list of `${build_kind}`s.
89+
/// - Parameter format: The `Format` to use.
90+
/// - Parameter leadingTrivia: Replaces the the last leading trivia if not nil.
91+
/// - Returns: A list of `${build_kind}`.
7292
public func build${kind}List(format: Format, leadingTrivia: Trivia? = nil) -> [${build_kind}] {
7393
[build${kind}(format: format, leadingTrivia: leadingTrivia)]
7494
}
@@ -80,6 +100,11 @@ extension ${kind}Buildable {
80100

81101
% for node in SYNTAX_NODES:
82102
% if node.is_buildable():
103+
% if node.description:
104+
% for line in dedented_lines(node.description):
105+
/// ${line}
106+
% end
107+
% end
83108
public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
84109
% for child in node.children:
85110
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token(), child.is_optional)
@@ -139,8 +164,17 @@ public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
139164

140165
% elif node.is_syntax_collection():
141166
// MARK: - Syntax collection
142-
public struct ${node.syntax_kind}: SyntaxBuildable {
167+
143168
% element_type = syntax_buildable_child_type(node.collection_element_type, node.collection_element, node.is_token())
169+
% if node.description:
170+
% for line in dedented_lines(node.description):
171+
/// ${line}
172+
% end
173+
% else:
174+
/// `${node.syntax_kind}` represents a collection of
175+
/// `${element_type}`s.
176+
% end
177+
public struct ${node.syntax_kind}: SyntaxBuildable {
144178
let elements: [${element_type}]
145179

146180
public init(_ elements: [${element_type}]) {

0 commit comments

Comments
 (0)