Skip to content

Commit 106fd09

Browse files
authored
Add documentation for --include-extended-types and --help flags. (#53)
* add documentation for the --include-extended-types flag * add documentation for how to access the --help flag * add 'Whats included' and 'Finding Extended Types' sections to Extended Types documentation * implement review feedback
1 parent 9b12589 commit 106fd09

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Generating Documentation for Extended Types
2+
3+
Generate documentation for the extensions you make to types from other modules.
4+
5+
## Overview
6+
7+
By default, the Swift-DocC plugin ignores extensions you make to types that are not from the module you're generating documentation for.
8+
9+
To include documentation for extended types, add the `--include-extended-types` flag to your invocations:
10+
11+
$ swift package generate-documentation --include-extended-types
12+
13+
> Note: Extension support is available when using Swift 5.8 or later and the Swift-DocC plugin 1.2 or later.
14+
15+
## Understanding What is Included by Default
16+
17+
Not everything that is declared in an extension is hidden behind the `--include-extended-types` flag. If the extension is declared in the same target as the type it is extending, the extension's contents will be included in the documentation by default.
18+
19+
```swift
20+
public struct Sloth { }
21+
22+
extension Sloth {
23+
// This function is included in the
24+
// documentation by default.
25+
public func wake() { /* ... */ }
26+
}
27+
28+
// `Collection` is from the standard library,
29+
// not the `SlothCreator` library, so this is
30+
// what we call an "extended type".
31+
extension Collection where Element == Sloth {
32+
// This property is not included in
33+
// the documentation by default.
34+
public func wake() {
35+
for sloth in self {
36+
sloth.wake()
37+
}
38+
}
39+
}
40+
```
41+
42+
## Finding Extended Types in your Documentation
43+
44+
Extended Types are part of the documentation archive of the target that declares the extensions.
45+
46+
![The rendered documentation for SlothCreator/Swift/Collection](extended-type-example)
47+
48+
Within that documentation archive, Extended Types are grouped by the Extended Module they belong to. You can find the latter on your documentation's landing page in a section called "Extended Modules". In our example from above, we have one Extended Module called "Swift" - the name of the standard library. This page can be referenced like this: ` ``SlothCreator/Swift`` `.
49+
50+
The Extended Type ` ``SlothCreator/Swift/Collection`` ` is a child of the Extended Module and is listed under "Extended Protocols" on the ` ``SlothCreator/Swift`` ` page.
51+
52+
> Note: The references above use the full path, including the name of the catalog's target, `SlothCreator`. This should help to understand the symbol's exact location, but usually isn't necessary.
53+
54+
<!-- Copyright (c) 2023 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/SwiftDocCPluginDocumentation/SwiftDocCPlugin.docc/SwiftDocCPlugin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ following from the command-line:
3333

3434
$ swift package generate-documentation
3535

36+
Use the `--help` flag to get a list of all supported arguments:
37+
38+
$ swift package plugin generate-documentation --help
39+
3640
The documentation on this site is focused on the Swift-DocC plugin specifically. For more
3741
general documentation on how to use Swift-DocC, see the documentation
3842
[here](https://www.swift.org/documentation/docc/).
@@ -43,6 +47,7 @@ general documentation on how to use Swift-DocC, see the documentation
4347

4448
- <doc:Generating-Documentation-for-a-Specific-Target>
4549
- <doc:Previewing-Documentation>
50+
- <doc:Generating-Documentation-for-Extended-Types>
4651

4752
### Publishing Documentation
4853

0 commit comments

Comments
 (0)