Skip to content

Commit 69066f5

Browse files
authored
Merge pull request #2034 from ahoppen/ahoppen/format-documentation
Format doc comments so they render better in docc
2 parents 35edf53 + 101c441 commit 69066f5

File tree

11 files changed

+1258
-846
lines changed

11 files changed

+1258
-846
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 71 additions & 53 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) {
@@ -1927,7 +1941,9 @@ public let DECL_NODES: [Node] = [
19271941
base: .decl,
19281942
nameForDiagnostics: "protocol",
19291943
documentation: """
1930-
A protocol declaration like the following.
1944+
A `protocol` declaration
1945+
1946+
An example of a protocol declaration is
19311947
19321948
```swift
19331949
protocol Example {
@@ -2048,61 +2064,63 @@ public let DECL_NODES: [Node] = [
20482064
base: .decl,
20492065
nameForDiagnostics: "struct",
20502066
documentation: """
2051-
A struct declaration like the following.
2067+
A `struct` declaration
20522068
2053-
```swift
2054-
struct SomeStruct {
2055-
let someMember: String
2056-
var anotherMember: Int
2057-
2058-
func foo() {
2059-
print(someMember)
2060-
}
2061-
2062-
mutating func bar() {
2063-
anotherMember = 42
2064-
}
2065-
}
2066-
```
2069+
An example of a struct declaration is
20672070
2068-
A struct declaration may be declared without any members.
2071+
```swift
2072+
struct SomeStruct {
2073+
let someMember: String
2074+
var anotherMember: Int
20692075
2070-
```swift
2071-
struct EmptyStruct {
2076+
func foo() {
2077+
print(someMember)
2078+
}
20722079
2073-
}
2074-
```
2080+
mutating func bar() {
2081+
anotherMember = 42
2082+
}
2083+
}
2084+
```
20752085
2076-
A struct declaration may include a type inheritance clause listing
2077-
one or more protocols the struct conforms to.
2086+
A struct declaration may be declared without any members.
20782087
2079-
The example below uses Hashable and Equatable protocols whose members
2080-
are automatically synthesized by the compiler if the struct contains
2081-
stored members that are themselves `Hashable` and `Equatable`.
2088+
```swift
2089+
struct EmptyStruct {
20822090
2083-
```swift
2084-
struct AdvancedStruct: Hashable, Equatable {
2085-
let someMember: String
2086-
var anotherMember: Int
2087-
}
2088-
```
2091+
}
2092+
```
20892093
2090-
A struct declaration may include a generic parameter clause as well
2091-
as a generic where clause.
2094+
A struct declaration may include a type inheritance clause listing
2095+
one or more protocols the struct conforms to.
20922096
2093-
```swift
2094-
struct Stack<Element> {
2095-
var items: [Element] = []
2096-
2097-
mutating func push(_ item: Element) {
2098-
items.append(item)
2099-
}
2100-
2101-
mutating func pop() -> Element {
2102-
return items.removeLast()
2103-
}
2104-
}
2105-
```
2097+
The example below uses Hashable and Equatable protocols whose members
2098+
are automatically synthesized by the compiler if the struct contains
2099+
stored members that are themselves `Hashable` and `Equatable`.
2100+
2101+
```swift
2102+
struct AdvancedStruct: Hashable, Equatable {
2103+
let someMember: String
2104+
var anotherMember: Int
2105+
}
2106+
```
2107+
2108+
A struct declaration may include a generic parameter clause as well
2109+
as a generic where clause.
2110+
2111+
```swift
2112+
struct Stack<Element> {
2113+
var items: [Element] = []
2114+
2115+
mutating func push(_ item: Element) {
2116+
items.append(item)
2117+
}
2118+
2119+
mutating func pop() -> Element {
2120+
return items.removeLast()
2121+
}
2122+
}
2123+
```
21062124
""",
21072125
traits: [
21082126
"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)