Skip to content

Commit 894fc62

Browse files
authored
Merge pull request #2232 from divalue/base-types-subtypes-documentation
Add documentation for base types with their subtypes
2 parents 7c6d4f7 + 8d828a8 commit 894fc62

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,31 @@ public class Node {
240240
)
241241
}
242242

243+
/// A doc comment that lists all the subtypes in which this node occurs as a base type in.
244+
public var subtypes: SwiftSyntax.Trivia {
245+
if kind == .unexpectedNodes {
246+
return []
247+
}
248+
249+
let list =
250+
SYNTAX_NODES
251+
.filter { $0.base == self.kind }
252+
.map { "- ``\($0.kind.syntaxType)``" }
253+
.joined(separator: "\n")
254+
255+
guard !list.isEmpty else {
256+
return []
257+
}
258+
259+
return .docCommentTrivia(
260+
from: """
261+
### Subtypes
262+
263+
\(list)
264+
"""
265+
)
266+
}
267+
243268
/// Construct the specification for a collection syntax node.
244269
///
245270
/// `base` must be `.syntaxCollection`.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import Utils
1717

1818
let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
1919
for node in SYNTAX_NODES where node.kind.isBase {
20+
let documentation = SwiftSyntax.Trivia(joining: [
21+
node.documentation,
22+
node.subtypes,
23+
])
2024
DeclSyntax(
2125
"""
2226
// MARK: - \(node.kind.syntaxType)
@@ -170,7 +174,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
170174

171175
try! StructDeclSyntax(
172176
"""
173-
\(node.documentation)
177+
\(documentation)
174178
\(node.apiAttributes())\
175179
public struct \(node.kind.syntaxType): \(node.kind.protocolType), SyntaxHashable
176180
"""

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@ public extension Syntax {
154154
}
155155
}
156156

157+
/// ### Subtypes
158+
///
159+
/// - ``AccessorDeclSyntax``
160+
/// - ``ActorDeclSyntax``
161+
/// - ``AssociatedTypeDeclSyntax``
162+
/// - ``ClassDeclSyntax``
163+
/// - ``DeinitializerDeclSyntax``
164+
/// - ``EditorPlaceholderDeclSyntax``
165+
/// - ``EnumCaseDeclSyntax``
166+
/// - ``EnumDeclSyntax``
167+
/// - ``ExtensionDeclSyntax``
168+
/// - ``FunctionDeclSyntax``
169+
/// - ``IfConfigDeclSyntax``
170+
/// - ``ImportDeclSyntax``
171+
/// - ``InitializerDeclSyntax``
172+
/// - ``MacroDeclSyntax``
173+
/// - ``MacroExpansionDeclSyntax``
174+
/// - ``MissingDeclSyntax``
175+
/// - ``OperatorDeclSyntax``
176+
/// - ``PoundSourceLocationSyntax``
177+
/// - ``PrecedenceGroupDeclSyntax``
178+
/// - ``ProtocolDeclSyntax``
179+
/// - ``StructDeclSyntax``
180+
/// - ``SubscriptDeclSyntax``
181+
/// - ``TypeAliasDeclSyntax``
182+
/// - ``VariableDeclSyntax``
157183
public struct DeclSyntax: DeclSyntaxProtocol, SyntaxHashable {
158184
public let _syntaxNode: Syntax
159185

@@ -430,6 +456,60 @@ public extension Syntax {
430456
}
431457
}
432458

459+
/// ### Subtypes
460+
///
461+
/// - ``ArrayExprSyntax``
462+
/// - ``ArrowExprSyntax``
463+
/// - ``AsExprSyntax``
464+
/// - ``AssignmentExprSyntax``
465+
/// - ``AwaitExprSyntax``
466+
/// - ``BinaryOperatorExprSyntax``
467+
/// - ``BooleanLiteralExprSyntax``
468+
/// - ``BorrowExprSyntax``
469+
/// - ``CanImportExprSyntax``
470+
/// - ``CanImportVersionInfoSyntax``
471+
/// - ``ClosureExprSyntax``
472+
/// - ``ConsumeExprSyntax``
473+
/// - ``CopyExprSyntax``
474+
/// - ``DeclReferenceExprSyntax``
475+
/// - ``DictionaryExprSyntax``
476+
/// - ``DiscardAssignmentExprSyntax``
477+
/// - ``EditorPlaceholderExprSyntax``
478+
/// - ``FloatLiteralExprSyntax``
479+
/// - ``ForceUnwrapExprSyntax``
480+
/// - ``FunctionCallExprSyntax``
481+
/// - ``GenericSpecializationExprSyntax``
482+
/// - ``IfExprSyntax``
483+
/// - ``InOutExprSyntax``
484+
/// - ``InfixOperatorExprSyntax``
485+
/// - ``IntegerLiteralExprSyntax``
486+
/// - ``IsExprSyntax``
487+
/// - ``KeyPathExprSyntax``
488+
/// - ``MacroExpansionExprSyntax``
489+
/// - ``MemberAccessExprSyntax``
490+
/// - ``MissingExprSyntax``
491+
/// - ``NilLiteralExprSyntax``
492+
/// - ``OptionalChainingExprSyntax``
493+
/// - ``PackElementExprSyntax``
494+
/// - ``PackExpansionExprSyntax``
495+
/// - ``PatternExprSyntax``
496+
/// - ``PostfixIfConfigExprSyntax``
497+
/// - ``PostfixOperatorExprSyntax``
498+
/// - ``PrefixOperatorExprSyntax``
499+
/// - ``RegexLiteralExprSyntax``
500+
/// - ``SequenceExprSyntax``
501+
/// - ``SimpleStringLiteralExprSyntax``
502+
/// - ``StringLiteralExprSyntax``
503+
/// - ``SubscriptCallExprSyntax``
504+
/// - ``SuperExprSyntax``
505+
/// - ``SwitchExprSyntax``
506+
/// - ``TernaryExprSyntax``
507+
/// - ``TryExprSyntax``
508+
/// - ``TupleExprSyntax``
509+
/// - ``TypeExprSyntax``
510+
/// - ``UnresolvedAsExprSyntax``
511+
/// - ``UnresolvedIsExprSyntax``
512+
/// - ``UnresolvedTernaryExprSyntax``
433513
public struct ExprSyntax: ExprSyntaxProtocol, SyntaxHashable {
434514
public let _syntaxNode: Syntax
435515

@@ -734,6 +814,15 @@ public extension Syntax {
734814
}
735815
}
736816

817+
/// ### Subtypes
818+
///
819+
/// - ``ExpressionPatternSyntax``
820+
/// - ``IdentifierPatternSyntax``
821+
/// - ``IsTypePatternSyntax``
822+
/// - ``MissingPatternSyntax``
823+
/// - ``TuplePatternSyntax``
824+
/// - ``ValueBindingPatternSyntax``
825+
/// - ``WildcardPatternSyntax``
737826
public struct PatternSyntax: PatternSyntaxProtocol, SyntaxHashable {
738827
public let _syntaxNode: Syntax
739828

@@ -993,6 +1082,25 @@ public extension Syntax {
9931082
}
9941083
}
9951084

1085+
/// ### Subtypes
1086+
///
1087+
/// - ``BreakStmtSyntax``
1088+
/// - ``ContinueStmtSyntax``
1089+
/// - ``DeferStmtSyntax``
1090+
/// - ``DiscardStmtSyntax``
1091+
/// - ``DoStmtSyntax``
1092+
/// - ``ExpressionStmtSyntax``
1093+
/// - ``FallThroughStmtSyntax``
1094+
/// - ``ForStmtSyntax``
1095+
/// - ``GuardStmtSyntax``
1096+
/// - ``LabeledStmtSyntax``
1097+
/// - ``MissingStmtSyntax``
1098+
/// - ``RepeatStmtSyntax``
1099+
/// - ``ReturnStmtSyntax``
1100+
/// - ``ThenStmtSyntax``
1101+
/// - ``ThrowStmtSyntax``
1102+
/// - ``WhileStmtSyntax``
1103+
/// - ``YieldStmtSyntax``
9961104
public struct StmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
9971105
public let _syntaxNode: Syntax
9981106

@@ -1262,6 +1370,26 @@ public extension Syntax {
12621370
}
12631371
}
12641372

1373+
/// ### Subtypes
1374+
///
1375+
/// - ``ArrayTypeSyntax``
1376+
/// - ``AttributedTypeSyntax``
1377+
/// - ``ClassRestrictionTypeSyntax``
1378+
/// - ``CompositionTypeSyntax``
1379+
/// - ``DictionaryTypeSyntax``
1380+
/// - ``FunctionTypeSyntax``
1381+
/// - ``IdentifierTypeSyntax``
1382+
/// - ``ImplicitlyUnwrappedOptionalTypeSyntax``
1383+
/// - ``MemberTypeSyntax``
1384+
/// - ``MetatypeTypeSyntax``
1385+
/// - ``MissingTypeSyntax``
1386+
/// - ``NamedOpaqueReturnTypeSyntax``
1387+
/// - ``OptionalTypeSyntax``
1388+
/// - ``PackElementTypeSyntax``
1389+
/// - ``PackExpansionTypeSyntax``
1390+
/// - ``SomeOrAnyTypeSyntax``
1391+
/// - ``SuppressedTypeSyntax``
1392+
/// - ``TupleTypeSyntax``
12651393
public struct TypeSyntax: TypeSyntaxProtocol, SyntaxHashable {
12661394
public let _syntaxNode: Syntax
12671395

0 commit comments

Comments
 (0)