Skip to content

Commit 101c441

Browse files
committed
Format doc comments so they render better in docc
Add a couple of line breaks to doc comments so they render more nicely in docc. For example, `DO NOT CONFORM TO THIS PROTOCOL YOURSELF!` should not show up in the abstract of the base syntax nodes
1 parent e42bece commit 101c441

File tree

11 files changed

+1254
-842
lines changed

11 files changed

+1254
-842
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 67 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ public let DECL_NODES: [Node] = [
242242
base: .decl,
243243
nameForDiagnostics: "associatedtype declaration",
244244
documentation: """
245-
An associated type declaration like the following.
245+
An `associatedtype` declaration
246+
247+
An example of an associatedtype declaration is
246248
247249
```swift
248250
associatedtype Item
@@ -332,7 +334,9 @@ public let DECL_NODES: [Node] = [
332334
base: .decl,
333335
nameForDiagnostics: "class",
334336
documentation: """
335-
A class declaration like the following.
337+
A `class` declaration
338+
339+
An example of a class declaration is
336340
337341
```swift
338342
class SomeClass {
@@ -498,7 +502,9 @@ public let DECL_NODES: [Node] = [
498502
base: .decl,
499503
nameForDiagnostics: "deinitializer",
500504
documentation: """
501-
A deinitializer declaration like the following.
505+
A `deint` declaration
506+
507+
An example of a deinitializer is
502508
503509
```swift
504510
deinit {
@@ -1135,7 +1141,9 @@ public let DECL_NODES: [Node] = [
11351141
base: .decl,
11361142
nameForDiagnostics: "import",
11371143
documentation: """
1138-
An import declaration like the following.
1144+
An `import` declaration
1145+
1146+
An example of an import declaration is
11391147
11401148
```swift
11411149
import Foundation
@@ -1180,7 +1188,11 @@ public let DECL_NODES: [Node] = [
11801188
.keyword(text: "func"),
11811189
.keyword(text: "inout"),
11821190
]),
1183-
documentation: "The kind of declaration being imported. For example, a struct can be imported from a specific module.",
1191+
documentation: """
1192+
The kind of declaration being imported.
1193+
1194+
A struct can be imported from a specific module.
1195+
""",
11841196
isOptional: true
11851197
),
11861198
Child(
@@ -1241,7 +1253,9 @@ public let DECL_NODES: [Node] = [
12411253
base: .decl,
12421254
nameForDiagnostics: "initializer",
12431255
documentation: """
1244-
An initializer declaration like the following.
1256+
An `init` declaration
1257+
1258+
An example of an initializer is
12451259
12461260
```swift
12471261
init(someParameter: Int) {
@@ -1900,7 +1914,9 @@ public let DECL_NODES: [Node] = [
19001914
base: .decl,
19011915
nameForDiagnostics: "protocol",
19021916
documentation: """
1903-
A protocol declaration like the following.
1917+
A `protocol` declaration
1918+
1919+
An example of a protocol declaration is
19041920
19051921
```swift
19061922
protocol Example {
@@ -2021,61 +2037,63 @@ public let DECL_NODES: [Node] = [
20212037
base: .decl,
20222038
nameForDiagnostics: "struct",
20232039
documentation: """
2024-
A struct declaration like the following.
2040+
A `struct` declaration
20252041
2026-
```swift
2027-
struct SomeStruct {
2028-
let someMember: String
2029-
var anotherMember: Int
2042+
An example of a struct declaration is
20302043
2031-
func foo() {
2032-
print(someMember)
2033-
}
2044+
```swift
2045+
struct SomeStruct {
2046+
let someMember: String
2047+
var anotherMember: Int
20342048
2035-
mutating func bar() {
2036-
anotherMember = 42
2037-
}
2038-
}
2039-
```
2049+
func foo() {
2050+
print(someMember)
2051+
}
20402052
2041-
A struct declaration may be declared without any members.
2053+
mutating func bar() {
2054+
anotherMember = 42
2055+
}
2056+
}
2057+
```
20422058
2043-
```swift
2044-
struct EmptyStruct {
2059+
A struct declaration may be declared without any members.
20452060
2046-
}
2047-
```
2061+
```swift
2062+
struct EmptyStruct {
20482063
2049-
A struct declaration may include a type inheritance clause listing
2050-
one or more protocols the struct conforms to.
2064+
}
2065+
```
20512066
2052-
The example below uses Hashable and Equatable protocols whose members
2053-
are automatically synthesized by the compiler if the struct contains
2054-
stored members that are themselves `Hashable` and `Equatable`.
2067+
A struct declaration may include a type inheritance clause listing
2068+
one or more protocols the struct conforms to.
20552069
2056-
```swift
2057-
struct AdvancedStruct: Hashable, Equatable {
2058-
let someMember: String
2059-
var anotherMember: Int
2060-
}
2061-
```
2070+
The example below uses Hashable and Equatable protocols whose members
2071+
are automatically synthesized by the compiler if the struct contains
2072+
stored members that are themselves `Hashable` and `Equatable`.
2073+
2074+
```swift
2075+
struct AdvancedStruct: Hashable, Equatable {
2076+
let someMember: String
2077+
var anotherMember: Int
2078+
}
2079+
```
20622080
2063-
A struct declaration may include a generic parameter clause as well
2064-
as a generic where clause.
2081+
A struct declaration may include a generic parameter clause as well
2082+
as a generic where clause.
20652083
2066-
```swift
2067-
struct Stack<Element> {
2068-
var items: [Element] = []
2084+
```swift
2085+
struct Stack<Element> {
2086+
var items: [Element] = []
20692087
2070-
mutating func push(_ item: Element) {
2071-
items.append(item)
2072-
}
2088+
mutating func push(_ item: Element) {
2089+
items.append(item)
2090+
}
20732091
2074-
mutating func pop() -> Element {
2075-
return items.removeLast()
2076-
}
2077-
}
2078-
```
2092+
mutating func pop() -> Element {
2093+
return items.removeLast()
2094+
}
2095+
}
2096+
```
20792097
""",
20802098
traits: [
20812099
"DeclGroup",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,9 @@ public let EXPR_NODES: [Node] = [
981981
base: .expr,
982982
nameForDiagnostics: "'is'",
983983
documentation: """
984-
An `is` expression like the following.
984+
Checks if an expression is of a given type.
985+
986+
An example of an `is` expression is
985987
986988
```swift
987989
value is Double

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
2121
"""
2222
// MARK: - \(node.kind.syntaxType)
2323
24-
/// Protocol to which all ``\(node.kind.syntaxType)`` nodes conform. Extension point to add
25-
/// common methods to all ``\(node.kind.syntaxType)`` nodes.
26-
/// DO NOT CONFORM TO THIS PROTOCOL YOURSELF!
24+
/// Protocol to which all ``\(node.kind.syntaxType)`` nodes conform.
25+
///
26+
/// Extension point to add common methods to all ``\(node.kind.syntaxType)`` nodes.
27+
///
28+
/// - Warning: Do not conform to this protocol yourself.
2729
public protocol \(node.kind.protocolType): \(raw: node.base.protocolType) {}
2830
"""
2931
)
@@ -33,7 +35,8 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
3335
"""
3436
/// Check whether the non-type erased version of this syntax node conforms to
3537
/// \(node.kind.protocolType).
36-
/// Note that this will incur an existential conversion.
38+
///
39+
/// - Note: This will incur an existential conversion.
3740
func isProtocol(_: \(node.kind.protocolType).Protocol) -> Bool {
3841
return self.asProtocol(\(node.kind.protocolType).self) != nil
3942
}
@@ -44,7 +47,8 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
4447
"""
4548
/// Return the non-type erased version of this syntax node if it conforms to
4649
/// \(node.kind.protocolType). Otherwise return nil.
47-
/// Note that this will incur an existential conversion.
50+
///
51+
/// - Note: This will incur an existential conversion.
4852
func asProtocol(_: \(node.kind.protocolType).Protocol) -> \(node.kind.protocolType)? {
4953
return self.asProtocol(SyntaxProtocol.self) as? \(node.kind.protocolType)
5054
}
@@ -131,9 +135,10 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
131135

132136
try InitializerDeclSyntax(
133137
"""
134-
/// Creates a ``\(node.kind.syntaxType)`` node from the given ``SyntaxData``. This assumes
135-
/// that the ``SyntaxData`` is of the correct kind. If it is not, the behaviour
136-
/// is undefined.
138+
/// Creates a ``\(node.kind.syntaxType)`` node from the given ``SyntaxData``.
139+
///
140+
/// - Warning: This assumes that the ``SyntaxData`` is of the correct kind.
141+
/// If it is not, the behaviour is undefined.
137142
internal init(_ data: SyntaxData)
138143
"""
139144
) {
@@ -192,7 +197,8 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
192197
"""
193198
/// Syntax nodes always conform to `\(node.kind.protocolType)`. This API is just
194199
/// added for consistency.
195-
/// Note that this will incur an existential conversion.
200+
///
201+
/// - Note: This will incur an existential conversion.
196202
@available(*, deprecated, message: "Expression always evaluates to true")
197203
public func isProtocol(_: \(raw: node.kind.protocolType).Protocol) -> Bool {
198204
return true
@@ -203,7 +209,8 @@ let syntaxBaseNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
203209
DeclSyntax(
204210
"""
205211
/// Return the non-type erased version of this syntax node.
206-
/// Note that this will incur an existential conversion.
212+
///
213+
/// - Note: This will incur an existential conversion.
207214
public func asProtocol(_: \(node.kind.protocolType).Protocol) -> \(node.kind.protocolType) {
208215
return Syntax(self).asProtocol(\(node.kind.protocolType).self)!
209216
}

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
6666

6767
DeclSyntax(
6868
"""
69-
/// Creates a ``\(node.kind.syntaxType)`` node from the given ``SyntaxData``. This assumes
70-
/// that the `SyntaxData` is of the correct kind. If it is not, the behaviour
71-
/// is undefined.
69+
/// Creates a ``\(node.kind.syntaxType)`` node from the given ``SyntaxData``.
70+
///
71+
/// - Warning: This assumes that the `SyntaxData` is of the correct kind.
72+
/// If it is not, the behaviour is undefined.
7273
internal init(_ data: SyntaxData) {
7374
precondition(data.raw.kind == .\(raw: node.varOrCaseName))
7475
self._syntaxNode = Syntax(data)
@@ -199,6 +200,7 @@ func syntaxNode(emitKind: SyntaxNodeKind) -> SourceFileSyntax {
199200
"""
200201
/// Adds the provided `element` to the node's `\(child.varOrCaseName)`
201202
/// collection.
203+
///
202204
/// - param element: The new `\(raw: childElt)` to add to the node's
203205
/// `\(child.varOrCaseName)` collection.
204206
/// - returns: A copy of the receiver with the provided `\(raw: childElt)`

0 commit comments

Comments
 (0)