You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document how to disambiguate symbol links using type signature information (#1095)
* Indent table markup for readability
* Add more details about how relative symbol links works
* Move examples about unambiguous links before "Ambiguous Symbol Links" section.
* Reorder list of supported disambiguation symbol types
* Add missing supported disambiguation symbol types
* Move the symbol type disambiguation example above the hash disambiguation example
* Update `Sloth/update(_:)` example to describe type disambiguation
rdar://136207820
* Add another more complicated type disambiguation example
rdar://136207820
* Minor refinements to the new documentation
* Fix 3 incomplete sentences in the new documentation
* Add a table of link disambiguation examples
* Apply suggestions from code review
Co-authored-by: Maya Epps <[email protected]>
---------
Co-authored-by: Maya Epps <[email protected]>
/// - Parameter energyLevel: The sloth's new energy level.
51
-
mutatingpublicfuncupdate(_energyLevel: Int) {
52
-
self.energyLevel= energyLevel
65
+
> Note:
66
+
If you prefer absolute symbol links you can prefix the symbol path with a leading slash followed by the name of the module to which that symbol belongs:
67
+
>
68
+
> ```markdown
69
+
> ``/SlothCreator/Sloth``
70
+
> ``/SlothCreator/Sloth/eat(_:quantity:)``
71
+
> ``/SlothCreator/Sloth/Food``
72
+
> ```
73
+
>
74
+
> DocC resolves absolute symbol links from the module's scope instead of the context that the link appears in.
75
+
76
+
Symbol paths are case-sensitive, meaning that symbols with the same name in different text casing are unambiguous.
77
+
For example, consider a `Sloth` structure with both a `color` property and a `Color` enumeration type:
78
+
79
+
```swift
80
+
public struct Sloth {
81
+
public var color: Color
82
+
83
+
public enum Color {
84
+
/* ... */
85
+
}
53
86
}
54
87
```
55
88
56
-
Both methods have an identical symbol path of `SlothCreator/Sloth/update(_:)`.
57
-
In this scenario, and to ensure uniqueness, DocC uses the symbol's unique
58
-
identifier instead of its name to disambiguate. DocC's warnings about ambiguous
59
-
symbol links suggests one disambiguation for each of the symbols that match the
60
-
ambiguous symbol path.
89
+
A ` ``Sloth/color`` ` symbol link unambiguously refers to the `color` property and a ` ``Sloth/Color`` ` symbol link unambiguously refers to the inner `Color` type.
90
+
91
+
#### Symbols with Multiple Language Representations
92
+
93
+
Symbol links to symbols that have representations in more than one programming language can use symbol paths in either source language.
94
+
For example, consider a `Sloth` class with `@objc` attributes:
You can write a symbol link to the Sloth initializer using the symbol path in either source language:
107
+
108
+
**Swift name**
61
109
62
110
```markdown
63
-
### Updating Sloths
64
-
- ``Sloth/update(_:)-4ko57``
65
-
- ``Sloth/update(_:)-jixx``
111
+
``Sloth/init(name:color:power:)``
112
+
```
113
+
114
+
**Objective-C name**
115
+
116
+
```markdown
117
+
``TLASloth/initWithName:color:power:``
66
118
```
67
119
68
-
In the example above, both symbols are functions, so you need the unique
69
-
identifiers to disambiguate the `Sloth/update(_:)` link.
120
+
#### Ambiguous Symbol Links
70
121
71
-
Unique identifiers aren't the only way to disambiguate symbol links. If a symbol
72
-
has a different type from the other symbols with the same symbol path, you can
73
-
use that symbol's type suffix to disambiguate the link and make the link refer
74
-
to that symbol. For example, consider a `Color` structure with `red`, `green`,
75
-
and `blue` properties for color components and static properties for a handful
76
-
of predefined color values:
122
+
In some cases a symbol's path isn't unique.
123
+
This makes it ambiguous what specific symbol a symbol link refers to.
124
+
For example, consider a `Color` structure with `red`, `green`, and `blue` properties for color components and static properties for a handful of predefined color values:
77
125
78
126
```swift
79
127
publicstructColor {
@@ -87,9 +135,8 @@ extension Color {
87
135
}
88
136
```
89
137
90
-
Both the `red` property and the `red` static property have a symbol path of
91
-
`Color/red`. Because these are different types of symbols you can disambiguate
92
-
`Color/red` with symbol type suffixes instead of the symbols' unique identifiers.
138
+
Both the `red` property and the `red` static property have a symbol path of `Color/red`.
139
+
Because these are different types of symbols you can disambiguate ` ``Color/red`` ` with a suffix indicating the symbol's type.
93
140
94
141
The following example shows a symbol link to the `red` property:
95
142
@@ -103,65 +150,146 @@ The following example shows a symbol link to the `red` static property:
103
150
``Color/red-type.property``
104
151
```
105
152
106
-
DocC supports the following symbol types for use in symbol links:
153
+
DocC supports the following symbol types as disambiguation in symbol links:
107
154
108
155
| Symbol type | Suffix |
109
156
|-------------------|-------------------|
110
157
| Enumeration |`-enum`|
111
158
| Enumeration case |`-enum.case`|
112
159
| Protocol |`-protocol`|
113
-
| Operator |`-func.op`|
114
160
| Typealias |`-typealias`|
115
-
|Function |`-func`|
161
+
|Associated Type|`-associatedtype`|
116
162
| Structure |`-struct`|
117
163
| Class |`-class`|
164
+
| Function |`-func`|
165
+
| Operator |`-func.op`|
166
+
| Property |`-property`|
118
167
| Type property |`-type.property`|
168
+
| Method |`-method`|
119
169
| Type method |`-type.method`|
170
+
| Subscript |`-subscript`|
120
171
| Type subscript |`-type.subscript`|
121
-
| Property |`-property`|
122
172
| Initializer |`-init`|
123
173
| Deinitializer |`-deinit`|
124
-
| Method |`-method`|
125
-
| Subscript |`-subscript`|
174
+
| Global variable |`-var`|
126
175
| Instance variable |`-ivar`|
127
176
| Macro |`-macro`|
128
177
| Module |`-module`|
178
+
| Namespace |`-namespace`|
179
+
| HTTP Request |`-httpRequest`|
180
+
| HTTP Parameter |`-httpParameter`|
181
+
| HTTP Response |`-httpResponse`|
182
+
| HTTPBody |`-httpBody`|
183
+
| Dictionary |`-dictionary`|
184
+
| Dictionary Key |`-dictionaryKey`|
129
185
130
-
Symbol type suffixes can include a source language identifier prefix — for
131
-
example, `-swift.enum` instead of `-enum`. However, the language
132
-
identifier doesn't disambiguate the link.
186
+
You can discover these symbol type suffixes from DocC's warnings about ambiguous symbol links.
187
+
DocC suggests one disambiguation for each of the symbols that match the ambiguous symbol path.
133
188
134
-
Symbol paths are case-sensitive, meaning that symbols with the same name in
135
-
different text casing don't need disambiguation.
189
+
Symbol type suffixes can include a source language identifier prefix---for example, `-swift.enum` instead of `-enum`.
190
+
However, the language identifier doesn't disambiguate the link.
136
191
137
-
Symbols that have representations in both Swift and Objective-C can use
138
-
symbol paths in either source language. For example, consider a `Sloth`
139
-
class with `@objc` attributes:
192
+
193
+
In the example above, both symbols that match the ambiguous symbol path were different types of symbol.
194
+
If the symbols that match the ambiguous symbol path have are the same type of symbol,
195
+
such as with overloaded methods in Swift, a symbol type suffix won't disambiguate the link.
196
+
In this scenario, DocC uses information from the symbols' type signatures to disambiguate.
197
+
For example, consider the `Sloth` structure---from the SlothCreator example---which has two different `update(_:)` methods:
/// - Parameter energyLevel: The sloth's new energy level.
210
+
mutatingpublicfuncupdate(_energyLevel: Int) {
211
+
self.energyLevel= energyLevel
148
212
}
149
213
```
150
214
151
-
You can write a symbol link to the Sloth initializer using the symbol path in either source language.
215
+
Both methods have an identical symbol path of `SlothCreator/Sloth/update(_:)`.
216
+
In this example there's only one parameter and its type is `Power` for the first overload and `Int` for the second overload.
217
+
DocC uses this parameter type information to suggest adding `(Power)` and `(Int)` to disambiguate each respective overload.
152
218
153
-
**Swift name**
219
+
The following example shows a topic group with disambiguated symbol links to both `Sloth/update(_:)` methods:
154
220
155
221
```markdown
156
-
``Sloth/init(name:color:power:)``
222
+
### Updating Sloths
223
+
224
+
- ``Sloth/update(_:)-(Power)``
225
+
- ``Sloth/update(_:)-(Int)``
157
226
```
158
227
159
-
**Objective-C name**
228
+
If there are more overloads with more parameters and return values,
229
+
DocC may suggest a combination of parameter types and return value types to uniquely disambiguate each overload.
230
+
For example consider a hypothetical weather service with these three overloads---with different parameter types and different return types---for a `forecast(for:at:)` method:
0 commit comments