Skip to content

Commit 3df63e8

Browse files
committed
Render references to experimental syntax nodes in code font instead of as docc links
Docc doesn’t like references to SPI types because they are not part of the public API.
1 parent ea71e1e commit 3df63e8

File tree

12 files changed

+67
-60
lines changed

12 files changed

+67
-60
lines changed

CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ struct GrammarGenerator {
3737
let optionality = child.isOptional ? "?" : ""
3838
switch child.kind {
3939
case .node(let kind):
40-
return "``\(kind.syntaxType)``\(optionality)"
40+
return "\(kind.doccLink)\(optionality)"
4141
case .nodeChoices(let choices):
4242
let choicesDescriptions = choices.map { grammar(for: $0) }
4343
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
4444
case .collection(kind: let kind, _, _, _):
45-
return "``\(kind.syntaxType)``\(optionality)"
45+
return "\(kind.doccLink)\(optionality)"
4646
case .token(let choices, _, _):
4747
if choices.count == 1 {
4848
return "\(grammar(for: choices.first!))\(optionality)"

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ public class Node {
224224
// This will repeat the syntax type before and after the dot, which is
225225
// a little unfortunate, but it's the only way I found to get docc to
226226
// generate a fully-qualified type + member.
227-
return " - ``\($0.node.syntaxType)``.``\($0.node.syntaxType)/\(childName)``"
227+
return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``"
228228
} else {
229-
return " - ``\($0.node.syntaxType)``"
229+
return " - \($0.node.doccLink)"
230230
}
231231
}
232232
.joined(separator: "\n")
@@ -249,7 +249,7 @@ public class Node {
249249
let list =
250250
SYNTAX_NODES
251251
.filter { $0.base == self.kind && !$0.isExperimental }
252-
.map { "- ``\($0.kind.syntaxType)``" }
252+
.map { "- \($0.kind.doccLink)" }
253253
.joined(separator: "\n")
254254

255255
guard !list.isEmpty else {
@@ -392,9 +392,9 @@ public struct CollectionNode {
392392
public var grammar: SwiftSyntax.Trivia {
393393
let grammar: String
394394
if let onlyElement = elementChoices.only {
395-
grammar = "``\(onlyElement.syntaxType)`` `*`"
395+
grammar = "\(onlyElement.doccLink) `*`"
396396
} else {
397-
grammar = "(\(elementChoices.map { "``\($0.syntaxType)``" }.joined(separator: " | "))) `*`"
397+
grammar = "(\(elementChoices.map { "\($0.doccLink)" }.joined(separator: " | "))) `*`"
398398
}
399399

400400
return .docCommentTrivia(
@@ -421,7 +421,3 @@ fileprivate extension Child {
421421
}
422422
}
423423
}
424-
425-
fileprivate extension Node {
426-
427-
}

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,17 @@ public enum SyntaxNodeKind: String, CaseIterable {
355355
}
356356
}
357357

358+
/// If this node is non-experimental a docc link wrapped in two backticks.
359+
///
360+
/// For experimental nodes, the node's type name in code font.
361+
public var doccLink: String {
362+
if let node = SYNTAX_NODE_MAP[self], node.isExperimental {
363+
return "`\(syntaxType)`"
364+
} else {
365+
return "``\(syntaxType)``"
366+
}
367+
}
368+
358369
/// For base nodes, the name of the corresponding protocol to which all the
359370
/// concrete nodes that have this base kind, conform.
360371
public var protocolType: TypeSyntax {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
2525
"""
2626
// MARK: - \(node.kind.syntaxType)
2727
28-
/// Protocol to which all ``\(node.kind.syntaxType)`` nodes conform.
28+
/// Protocol to which all \(raw: node.kind.doccLink) nodes conform.
2929
///
30-
/// Extension point to add common methods to all ``\(node.kind.syntaxType)`` nodes.
30+
/// Extension point to add common methods to all \(raw: node.kind.doccLink) nodes.
3131
///
3232
/// - Warning: Do not conform to this protocol yourself.
3333
\(node.apiAttributes())\
@@ -77,23 +77,23 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
7777
return self.as(S.self)!
7878
}
7979
80-
/// Checks if the current syntax node can be upcast to its base node type (``\#(node.kind.syntaxType)``).
80+
/// Checks if the current syntax node can be upcast to its base node type (\#(raw: node.kind.doccLink)).
8181
///
8282
/// - Returns: `true` since the node can always be upcast to its base node.
8383
@available(*, deprecated, message: "This cast will always succeed")
8484
public func `is`(_ syntaxType: \#(node.kind.syntaxType).Type) -> Bool {
8585
return true
8686
}
8787
88-
/// Attempts to upcast the current syntax node to its base node type (``\#(node.kind.syntaxType)``).
88+
/// Attempts to upcast the current syntax node to its base node type (\#(raw: node.kind.doccLink)).
8989
///
9090
/// - Returns: The base node created from the current syntax node, as the node can always be upcast to its base type.
9191
@available(*, deprecated, message: "Use `\#(node.kind.syntaxType).init` for upcasting")
9292
public func `as`(_ syntaxType: \#(node.kind.syntaxType).Type) -> \#(node.kind.syntaxType)? {
9393
return \#(node.kind.syntaxType)(self)
9494
}
9595
96-
/// Force-upcast the current syntax node to its base node type (``\#(node.kind.syntaxType)``).
96+
/// Force-upcast the current syntax node to its base node type (\#(raw: node.kind.doccLink)).
9797
///
9898
/// - Returns: The base node created from the current syntax node, as the node can always be upcast to its base type.
9999
@available(*, deprecated, message: "Use `\#(node.kind.syntaxType).init` for upcasting")
@@ -182,7 +182,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
182182

183183
DeclSyntax(
184184
"""
185-
/// Create a ``\(node.kind.syntaxType)`` node from a specialized syntax node.
185+
/// Create a \(raw: node.kind.doccLink) node from a specialized syntax node.
186186
public init(_ syntax: some \(node.kind.protocolType)) {
187187
// We know this cast is going to succeed. Go through init(_: SyntaxData)
188188
// to do a sanity check and verify the kind matches in debug builds and get
@@ -194,7 +194,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
194194

195195
DeclSyntax(
196196
"""
197-
/// Create a ``\(node.kind.syntaxType)`` node from a specialized optional syntax node.
197+
/// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node.
198198
public init?(_ syntax: (some \(node.kind.protocolType))?) {
199199
guard let syntax = syntax else { return nil }
200200
self.init(syntax)
@@ -215,7 +215,7 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
215215

216216
DeclSyntax(
217217
"""
218-
/// Create a ``\(node.kind.syntaxType)`` node from a specialized optional syntax node.
218+
/// Create a \(raw: node.kind.doccLink) node from a specialized optional syntax node.
219219
public init?(fromProtocol syntax: \(node.kind.protocolType)?) {
220220
guard let syntax = syntax else { return nil }
221221
self.init(fromProtocol: syntax)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock
5757
} else {
5858
DeclSyntax(
5959
"""
60-
/// Checks if the current syntax node can be cast to ``\(syntaxNodeKind.syntaxType)``.
60+
/// Checks if the current syntax node can be cast to \(raw: syntaxNodeKind.doccLink).
6161
///
6262
/// - Returns: `true` if the node can be cast, `false` otherwise.
6363
\(apiAttributes)\
@@ -69,9 +69,9 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock
6969

7070
DeclSyntax(
7171
"""
72-
/// Attempts to cast the current syntax node to ``\(syntaxNodeKind.syntaxType)``.
72+
/// Attempts to cast the current syntax node to \(raw: syntaxNodeKind.doccLink).
7373
///
74-
/// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``, or `nil` if the cast fails.
74+
/// - Returns: An instance of \(raw: syntaxNodeKind.doccLink), or `nil` if the cast fails.
7575
\(apiAttributes)\
7676
public func `as`(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType)? {
7777
return \(syntaxNodeKind.syntaxType).init(self)
@@ -81,9 +81,9 @@ func choiceNodeCastingMethods(for syntaxNodeKind: SyntaxNodeKind) -> MemberBlock
8181

8282
DeclSyntax(
8383
"""
84-
/// Force-casts the current syntax node to ``\(syntaxNodeKind.syntaxType)``.
84+
/// Force-casts the current syntax node to \(raw: syntaxNodeKind.doccLink).
8585
///
86-
/// - Returns: An instance of ``\(syntaxNodeKind.syntaxType)``.
86+
/// - Returns: An instance of \(raw: syntaxNodeKind.doccLink).
8787
/// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast.
8888
\(apiAttributes)\
8989
public func cast(_ syntaxType: \(syntaxNodeKind.syntaxType).Type) -> \(syntaxNodeKind.syntaxType) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
122122
if (node.base == .syntax || node.base == .syntaxCollection) && node.kind != .missing {
123123
DeclSyntax(
124124
"""
125-
/// Visit a ``\(node.kind.syntaxType)``.
125+
/// Visit a \(raw: node.kind.doccLink).
126126
/// - Parameter node: the node that is being visited
127127
/// - Returns: the rewritten node
128128
\(node.apiAttributes())\
@@ -134,7 +134,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
134134
} else {
135135
DeclSyntax(
136136
"""
137-
/// Visit a ``\(node.kind.syntaxType)``.
137+
/// Visit a \(raw: node.kind.doccLink).
138138
/// - Parameter node: the node that is being visited
139139
/// - Returns: the rewritten node
140140
\(node.apiAttributes())\

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let syntaxVisitorFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
5353
for node in SYNTAX_NODES where !node.kind.isBase {
5454
DeclSyntax(
5555
"""
56-
/// Visiting ``\(node.kind.syntaxType)`` specifically.
56+
/// Visiting \(raw: node.kind.doccLink) specifically.
5757
/// - Parameter node: the node we are visiting.
5858
/// - Returns: how should we continue visiting.
5959
\(node.apiAttributes())\
@@ -65,7 +65,7 @@ let syntaxVisitorFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6565

6666
DeclSyntax(
6767
"""
68-
/// The function called after visiting ``\(node.kind.syntaxType)`` and its descendants.
68+
/// The function called after visiting \(raw: node.kind.doccLink) and its descendants.
6969
/// - node: the node we just finished visiting.
7070
\(node.apiAttributes())\
7171
open func visitPost(_ node: \(node.kind.syntaxType)) {}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// MARK: - DeclSyntax
1616

17-
/// Protocol to which all ``DeclSyntax`` nodes conform.
17+
/// Protocol to which all ``DeclSyntax`` nodes conform.
1818
///
1919
/// Extension point to add common methods to all ``DeclSyntax`` nodes.
2020
///
@@ -315,7 +315,7 @@ public extension _LeafDeclSyntaxNodeProtocol {
315315

316316
// MARK: - ExprSyntax
317317

318-
/// Protocol to which all ``ExprSyntax`` nodes conform.
318+
/// Protocol to which all ``ExprSyntax`` nodes conform.
319319
///
320320
/// Extension point to add common methods to all ``ExprSyntax`` nodes.
321321
///
@@ -673,7 +673,7 @@ public extension _LeafExprSyntaxNodeProtocol {
673673

674674
// MARK: - PatternSyntax
675675

676-
/// Protocol to which all ``PatternSyntax`` nodes conform.
676+
/// Protocol to which all ``PatternSyntax`` nodes conform.
677677
///
678678
/// Extension point to add common methods to all ``PatternSyntax`` nodes.
679679
///
@@ -940,7 +940,7 @@ public extension _LeafPatternSyntaxNodeProtocol {
940940

941941
// MARK: - StmtSyntax
942942

943-
/// Protocol to which all ``StmtSyntax`` nodes conform.
943+
/// Protocol to which all ``StmtSyntax`` nodes conform.
944944
///
945945
/// Extension point to add common methods to all ``StmtSyntax`` nodes.
946946
///
@@ -1226,7 +1226,7 @@ public extension _LeafStmtSyntaxNodeProtocol {
12261226

12271227
// MARK: - TypeSyntax
12281228

1229-
/// Protocol to which all ``TypeSyntax`` nodes conform.
1229+
/// Protocol to which all ``TypeSyntax`` nodes conform.
12301230
///
12311231
/// Extension point to add common methods to all ``TypeSyntax`` nodes.
12321232
///

Sources/SwiftSyntax/generated/SyntaxCollections.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ public struct LabeledExprListSyntax: SyntaxCollection, SyntaxHashable {
880880
///
881881
/// ### Children
882882
///
883-
/// ``LifetimeSpecifierArgumentSyntax`` `*`
883+
/// `LifetimeSpecifierArgumentSyntax` `*`
884884
#if compiler(>=5.8)
885885
@_spi(ExperimentalLanguageFeatures)
886886
#endif
@@ -1675,7 +1675,7 @@ public struct TupleTypeElementListSyntax: SyntaxCollection, SyntaxHashable {
16751675

16761676
/// ### Children
16771677
///
1678-
/// (``SimpleTypeSpecifierSyntax`` | ``LifetimeTypeSpecifierSyntax``) `*`
1678+
/// (``SimpleTypeSpecifierSyntax`` | `LifetimeTypeSpecifierSyntax`) `*`
16791679
///
16801680
/// ### Contained in
16811681
///
@@ -1748,7 +1748,7 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable {
17481748
return self.as(SimpleTypeSpecifierSyntax.self)!
17491749
}
17501750

1751-
/// Checks if the current syntax node can be cast to ``LifetimeTypeSpecifierSyntax``.
1751+
/// Checks if the current syntax node can be cast to `LifetimeTypeSpecifierSyntax`.
17521752
///
17531753
/// - Returns: `true` if the node can be cast, `false` otherwise.
17541754
#if compiler(>=5.8)
@@ -1758,19 +1758,19 @@ public struct TypeSpecifierListSyntax: SyntaxCollection, SyntaxHashable {
17581758
return self.as(syntaxType) != nil
17591759
}
17601760

1761-
/// Attempts to cast the current syntax node to ``LifetimeTypeSpecifierSyntax``.
1761+
/// Attempts to cast the current syntax node to `LifetimeTypeSpecifierSyntax`.
17621762
///
1763-
/// - Returns: An instance of ``LifetimeTypeSpecifierSyntax``, or `nil` if the cast fails.
1763+
/// - Returns: An instance of `LifetimeTypeSpecifierSyntax`, or `nil` if the cast fails.
17641764
#if compiler(>=5.8)
17651765
@_spi(ExperimentalLanguageFeatures)
17661766
#endif
17671767
public func `as`(_ syntaxType: LifetimeTypeSpecifierSyntax.Type) -> LifetimeTypeSpecifierSyntax? {
17681768
return LifetimeTypeSpecifierSyntax.init(self)
17691769
}
17701770

1771-
/// Force-casts the current syntax node to ``LifetimeTypeSpecifierSyntax``.
1771+
/// Force-casts the current syntax node to `LifetimeTypeSpecifierSyntax`.
17721772
///
1773-
/// - Returns: An instance of ``LifetimeTypeSpecifierSyntax``.
1773+
/// - Returns: An instance of `LifetimeTypeSpecifierSyntax`.
17741774
/// - Warning: This function will crash if the cast is not possible. Use `as` to safely attempt a cast.
17751775
#if compiler(>=5.8)
17761776
@_spi(ExperimentalLanguageFeatures)

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ open class SyntaxRewriter {
668668
return StmtSyntax(visitChildren(node))
669669
}
670670

671-
/// Visit a ``DoExprSyntax``.
671+
/// Visit a `DoExprSyntax`.
672672
/// - Parameter node: the node that is being visited
673673
/// - Returns: the rewritten node
674674
#if compiler(>=5.8)
@@ -1203,7 +1203,7 @@ open class SyntaxRewriter {
12031203
return visitChildren(node)
12041204
}
12051205

1206-
/// Visit a ``LifetimeSpecifierArgumentListSyntax``.
1206+
/// Visit a `LifetimeSpecifierArgumentListSyntax`.
12071207
/// - Parameter node: the node that is being visited
12081208
/// - Returns: the rewritten node
12091209
#if compiler(>=5.8)
@@ -1213,7 +1213,7 @@ open class SyntaxRewriter {
12131213
return visitChildren(node)
12141214
}
12151215

1216-
/// Visit a ``LifetimeSpecifierArgumentSyntax``.
1216+
/// Visit a `LifetimeSpecifierArgumentSyntax`.
12171217
/// - Parameter node: the node that is being visited
12181218
/// - Returns: the rewritten node
12191219
#if compiler(>=5.8)
@@ -1223,7 +1223,7 @@ open class SyntaxRewriter {
12231223
return visitChildren(node)
12241224
}
12251225

1226-
/// Visit a ``LifetimeSpecifierArgumentsSyntax``.
1226+
/// Visit a `LifetimeSpecifierArgumentsSyntax`.
12271227
/// - Parameter node: the node that is being visited
12281228
/// - Returns: the rewritten node
12291229
#if compiler(>=5.8)
@@ -1233,7 +1233,7 @@ open class SyntaxRewriter {
12331233
return visitChildren(node)
12341234
}
12351235

1236-
/// Visit a ``LifetimeTypeSpecifierSyntax``.
1236+
/// Visit a `LifetimeTypeSpecifierSyntax`.
12371237
/// - Parameter node: the node that is being visited
12381238
/// - Returns: the rewritten node
12391239
#if compiler(>=5.8)
@@ -1838,7 +1838,7 @@ open class SyntaxRewriter {
18381838
return ExprSyntax(visitChildren(node))
18391839
}
18401840

1841-
/// Visit a ``ThenStmtSyntax``.
1841+
/// Visit a `ThenStmtSyntax`.
18421842
/// - Parameter node: the node that is being visited
18431843
/// - Returns: the rewritten node
18441844
#if compiler(>=5.8)

0 commit comments

Comments
 (0)