Skip to content

Commit 5a690ce

Browse files
Update contributor documentation to reflect changes in input discovery (#1060)
* Update contributor documentation about documentation input discovery rdar://139494777 * Update copyright year for updated contributor documentation article * Avoid deprecated API in code example in contributor documentation * Mention catalog content file extensions in top-level contributor documentation * Add more documentation for `DocumentationContext/InputsProvider` * Correct "catalog" terminology in some contributor documentation * Add more documentation for `DocumentationBundle` * Apply suggestions from code review Co-authored-by: Maya Epps <[email protected]> --------- Co-authored-by: Maya Epps <[email protected]>
1 parent 926dcc4 commit 5a690ce

File tree

9 files changed

+217
-149
lines changed

9 files changed

+217
-149
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationBundle.swift

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,30 @@
1010

1111
import Foundation
1212

13-
/**
14-
A documentation bundle.
15-
16-
A documentation bundle stores all of the authored content and metadata for a collection of topics and/or frameworks.
17-
18-
No content data is immediately loaded when creating a `DocumentationBundle` except for its `Info.plist`. Its purpose is to provide paths on disk for documentation resources.
19-
20-
## Topics
21-
### Bundle Metadata
22-
23-
- ``displayName``
24-
- ``identifier``
25-
- ``version``
26-
*/
13+
/// A collection of the build inputs for a unit of documentation.
14+
///
15+
/// A unit of documentation may for example cover a framework, library, or tool.
16+
/// Projects or packages may have multiple units of documentation to represent the different consumable products in that project or package.
17+
///
18+
/// ## Topics
19+
///
20+
/// ### Input files
21+
///
22+
/// - ``markupURLs``
23+
/// - ``symbolGraphURLs``
24+
/// - ``miscResourceURLs``
25+
///
26+
/// ### Render customization
27+
///
28+
/// - ``customHeader``
29+
/// - ``customFooter``
30+
/// - ``themeSettings``
31+
///
32+
/// ### Metadata
33+
///
34+
/// - ``info``
35+
/// - ``displayName``
36+
/// - ``identifier``
2737
public struct DocumentationBundle {
2838
public enum PropertyListError: DescribedError {
2939
case invalidVersionString(String)
@@ -39,21 +49,17 @@ public struct DocumentationBundle {
3949
}
4050
}
4151

42-
/// Information about this documentation bundle that's unrelated to its documentation content.
52+
/// Non-content information or metadata about this unit of documentation.
4353
public let info: Info
4454

45-
/**
46-
The bundle's human-readable display name.
47-
*/
55+
/// A human-readable display name for this unit of documentation.
4856
public var displayName: String {
4957
info.displayName
5058
}
5159

52-
/**
53-
The documentation bundle identifier.
54-
55-
An identifier string that specifies the app type of the bundle. The string should be in reverse DNS format using only the Roman alphabet in upper and lower case (A–Z, a–z), the dot (“.”), and the hyphen (“-”).
56-
*/
60+
/// A identifier for this unit of documentation
61+
///
62+
/// The string is typically in reverse DNS format using only the Roman alphabet in upper and lower case (A–Z, a–z), the dot (“.”), and the hyphen (“-”).
5763
public var identifier: String {
5864
info.identifier
5965
}
@@ -72,13 +78,25 @@ public struct DocumentationBundle {
7278
@available(*, deprecated, message: "This deprecated API will be removed after 6.1 is released")
7379
public var attributedCodeListings: [String: AttributedCodeListing] = [:]
7480

75-
/// Symbol Graph JSON files for the modules documented by this bundle.
81+
/// Symbol graph JSON input files for the module that's represented by this unit of documentation.
82+
///
83+
/// Tutorial or article-only documentation won't have any symbol graph JSON files.
84+
///
85+
/// ## See Also
86+
///
87+
/// - ``DocumentationBundleFileTypes/isSymbolGraphFile(_:)``
7688
public let symbolGraphURLs: [URL]
7789

78-
/// DocC Markup files of the bundle.
90+
/// Documentation markup input files for this unit of documentation.
91+
///
92+
/// Documentation markup files include both articles, documentation extension files, and tutorial files.
93+
///
94+
/// ## See Also
95+
///
96+
/// - ``DocumentationBundleFileTypes/isMarkupFile(_:)``
7997
public let markupURLs: [URL]
8098

81-
/// Miscellaneous resources of the bundle.
99+
/// Miscellaneous resources (for example images, videos, or downloadable assets) for this unit of documentation.
82100
public let miscResourceURLs: [URL]
83101

84102
/// A custom HTML file to use as the header for rendered output.
@@ -90,21 +108,19 @@ public struct DocumentationBundle {
90108
/// A custom JSON settings file used to theme renderer output.
91109
public let themeSettings: URL?
92110

93-
/**
94-
A URL prefix to be appended to the relative presentation URL.
95-
96-
This is used when a bundle's documentation is hosted in a known location.
97-
*/
111+
/// A URL prefix to be appended to the relative presentation URL.
112+
///
113+
/// This is used when a built documentation is hosted in a known location.
98114
public let baseURL: URL
99115

100-
/// Creates a documentation bundle.
116+
/// Creates a new collection of build inputs for a unit of documentation.
101117
///
102118
/// - Parameters:
103-
/// - info: Information about the bundle.
119+
/// - info: Non-content information or metadata about this unit of documentation.
104120
/// - baseURL: A URL prefix to be appended to the relative presentation URL.
105-
/// - symbolGraphURLs: Symbol Graph JSON files for the modules documented by the bundle.
106-
/// - markupURLs: DocC Markup files of the bundle.
107-
/// - miscResourceURLs: Miscellaneous resources of the bundle.
121+
/// - symbolGraphURLs: Symbol graph JSON input files for the module that's represented by this unit of documentation.
122+
/// - markupURLs: Documentation markup input files for this unit of documentation.
123+
/// - miscResourceURLs: Miscellaneous resources (for example images, videos, or downloadable assets) for this unit of documentation.
108124
/// - customHeader: A custom HTML file to use as the header for rendered output.
109125
/// - customFooter: A custom HTML file to use as the footer for rendered output.
110126
/// - themeSettings: A custom JSON settings file used to theme renderer output.

Sources/SwiftDocC/Infrastructure/Input Discovery/DocumentationInputsProvider.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@ import SymbolKit
1414
extension DocumentationContext {
1515

1616
/// A type that provides inputs for a unit of documentation.
17+
///
18+
/// The inputs provider discovers documentation catalogs on the file system and creates a ``DocumentationBundle`` from the discovered catalog content.
19+
///
20+
/// The input provider categorizes the catalog content based on corresponding ``DocumentationBundleFileTypes`` conditions:
21+
///
22+
/// Category | Condition
23+
/// ---------------------------------------- | -------------------------------------------------
24+
/// ``DocumentationBundle/markupURLs`` | ``DocumentationBundleFileTypes/isMarkupFile(_:)``
25+
/// ``DocumentationBundle/symbolGraphURLs`` | ``DocumentationBundleFileTypes/isSymbolGraphFile(_:)``
26+
/// ``DocumentationBundle/info`` | ``DocumentationBundleFileTypes/isInfoPlistFile(_:)``
27+
/// ``DocumentationBundle/themeSettings`` | ``DocumentationBundleFileTypes/isThemeSettingsFile(_:)``
28+
/// ``DocumentationBundle/customHeader`` | ``DocumentationBundleFileTypes/isCustomHeader(_:)``
29+
/// ``DocumentationBundle/customFooter`` | ``DocumentationBundleFileTypes/isCustomFooter(_:)``
30+
/// ``DocumentationBundle/miscResourceURLs`` | Any file not already matched above.
31+
///
32+
/// ## Topics
33+
///
34+
/// ### Catalog discovery
35+
///
36+
/// Discover documentation catalogs and create documentation build inputs from the discovered catalog's content.
37+
///
38+
/// - ``findCatalog(startingPoint:allowArbitraryCatalogDirectories:)``
39+
/// - ``makeInputs(contentOf:options:)``
40+
///
41+
/// ### Input discovery
42+
///
43+
/// Discover documentation build inputs from a mix of discovered documentation catalogs and other command line options.
44+
///
45+
/// - ``inputsAndDataProvider(startingPoint:allowArbitraryCatalogDirectories:options:)``
46+
///
47+
/// ### Errors
48+
///
49+
/// Errors that the inputs provider can raise while validating the discovered inputs.
50+
///
51+
/// - ``MultipleCatalogsError``
52+
/// - ``NotEnoughInformationError``
53+
/// - ``InputsFromSymbolGraphError``
1754
package struct InputsProvider {
1855
/// The file manager that the provider uses to read file and directory contents from the file system.
1956
private var fileManager: FileManagerProtocol

Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ Combine code comments with markup prose to produce structured, semantic document
44

55
## Overview
66

7-
DocC comes with built-in support for several types of input files. You organize these files by placing them in a folder with a `.docc` extension. This folder is called a documentation bundle, and can include these file types:
7+
DocC comes with built-in support for several types of input files. You group these files by placing them in a folder with a `.docc` extension. This folder is called a documentation catalog, and can include these file types:
88

9-
- Symbol-graph files, in JSON format, that describe available symbols in a framework.
10-
- Lightweight markdown files that contain free-form articles and more.
11-
- Tutorial files that include dynamic, learning content.
12-
- Asset files like images, videos, and archived projects for download.
13-
- An `Info.plist` file that contains metadata about the bundle.
9+
- Lightweight markdown files that contain free-form articles or additional symbol documentation, with an `.md` extension.
10+
- Tutorial files that include dynamic learning content, with a `.tutorial` extension.
11+
- Asset files like images, videos, and archived projects for download, with known extensions like `.png`, `.jpg`, `.mov`, and `.zip`.
12+
- Symbol-graph files that describe the symbols of your API, with an `.symbols.json` extension.
13+
- An `Info.plist` file with optional metadata about the documentation.
14+
- A `theme-settings.json` with theming customizations for the rendered output.
1415

15-
SwiftDocC provides the APIs you use to load a bundle, parse the symbol-graph meta-information, extract symbol documentation, and optionally pair that symbol documentation with external file content. DocC represents the compiled documentation in an in-memory model that you can further convert in a persistable representation for writing to disk.
16+
SwiftDocC provides the APIs you use to discover documentation inputs, load catalog content, parse the symbol-graph meta-information, extract symbol documentation, and pair that symbol documentation with external file content.
17+
DocC represents the compiled documentation in an in-memory model that you can further convert in a persistable representation for writing to disk.
1618

1719
## Topics
1820

@@ -22,7 +24,7 @@ SwiftDocC provides the APIs you use to load a bundle, parse the symbol-graph met
2224

2325
### Content Discovery
2426

25-
- <doc:DocumentationWorkspaceGroup>
27+
- <doc:InputDiscovery>
2628
- <doc:DocumentationContextGroup>
2729

2830
### Resolving documentation links

Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC/Benchmarking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When you are working on a PR to add a feature or fix a bug you should evaluate t
88

99
## Running a benchmark
1010

11-
To benchmark the `convert` command with a given documentation bundle `MyFramework.docc` run:
11+
To benchmark the `convert` command with a given documentation catalog `MyFramework.docc` run:
1212

1313
```
1414
swift run --package-path bin/benchmark benchmark --docc-arguments convert MyFramework.docc
@@ -80,4 +80,4 @@ benchmark(add: BundlesCount(context: context))
8080
- ``benchmark(end:benchmarkLog:)``
8181
- ``benchmark(wrap:benchmarkLog:body:)``
8282

83-
<!-- Copyright (c) 2021-2022 Apple Inc and the Swift Project authors. All Rights Reserved. -->
83+
<!-- Copyright (c) 2021-2024 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC/CompilerPipeline.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ Get to know the steps involved in documentation compilation.
66

77
This article describes the discrete and sequential steps of compiling documentation with DocC.
88

9-
DocC starts with content discovery by parsing the documentation sources in your documentation bundle. Next, it validates and semantically analyzes them and then builds an in-memory model of the compiled documentation. Once the in-memory model is finalized, DocC converts each topic into a persistable representation it can store on disk.
10-
11-
To use the compiled documentation, either query the in-memory model directly or convert its nodes to their render-friendly representation. For example, the `SwiftDocCUtilities` framework enumerates all the nodes in DocC's in-memory model, converts each node for rendering, and finally writes the complete documentation to the disk.
9+
DocC starts with input discovery by categorizing the documentation sources in your documentation catalog. Next, it loads and parses the those inputs to create in-memory models of the documentation pages. Once the in-memory model is finalized, DocC converts each topic into a persistable, render-friendly representation it can store on disk.
1210

1311
### Discovery
1412

15-
DocC starts discovery by creating a ``DocumentationWorkspace`` to interact with the file system and a ``DocumentationContext`` that manages the in-memory model for the built documentation.
13+
DocC starts by creating a ``DocumentationContext/InputsProvider`` to discover the inputs from the user-provided command line arguments. These inputs are:
1614

17-
When a documentation bundle is found in the workspace by a ``DocumentationWorkspaceDataProvider``, the following files are recognized and processed (others are ignored):
15+
- Markup files, tutorial files, and assets (for example images)
16+
- Symbol graph files, describing the symbols in a given module (types, functions, variables, etc.) and their relationships (inheritance, conformance, etc.)
17+
- Meta information about this "unit" of documentation (for example a custom display name)
18+
- Customizations to the render template.
1819

19-
- An `Info.plist` file containing meta information like the bundle display name.
20-
- Symbol-graph files with the `.symbols.json` extension.
21-
- Authored markup files with an `.md` extension
22-
- Authored tutorial files with a `.tutorial` extension
23-
- Additional documentation assets with known extensions like `.png`, `.jpg`, `.mov`, and `.zip`.
20+
Markup, tutorials, assets, and render-template-customization can only be discovered as files inside of a documentation catalog (`.docc` directory).
21+
Symbol graph files can either be discovered as files inside of a documentation catalog or as additional files provided via user-provided command line arguments.
22+
Meta information can either be discovered from an optional top-level `Info.plist` file inside of a documentation catalog or as provided values via user-provided command line arguments. All meta information is optional.
2423

25-
You can organize the files in any way, as long as `Info.plist` is in the root of the directory tree. Here is an example of a bundle, that groups topic files in logical groups with an additional directory for shared asset files:
24+
You can organize the files inside the documentation catalog according to your preference,
25+
as long as the optional `Info.plist`--containing optional meta information--and the optional render customization files are top-level.
26+
For example, this catalog groups files based on their topic with an additional directory for shared asset files:
2627

2728
```none
2829
SwiftDocC.docc
@@ -45,9 +46,10 @@ SwiftDocC.docc
4546

4647
### Analysis and Registration
4748

48-
This phase starts with registering all symbols from the available symbol graphs into a documentation *topic graph* in memory.
49+
This phase starts with creating a ``DocumentationContext`` using the discovered inputs from the previous phase.
50+
This begins loading and registering the inputs with the context.
4951

50-
The symbol graph files are machine generated and describe all available symbols in a framework (types, functions, variables, etc.) and their relationships, for example, inheritance and conformance.
52+
The first input that the context registers is the symbol information. The symbol information comes from "symbol graph files" which are machine generated and describe all available symbols in a framework (types, functions, variables, etc.) and their relationships (inheritance, conformance, etc.).
5153

5254
Each symbol becomes a documentation node in the topic graph and thus a documentation *topic* (an entity in the documentation model). The symbol's topic could optionally be extended with authored documentation from a markup file.
5355

@@ -57,7 +59,7 @@ Next, all the remaining markup files are analyzed and converted to documents (fo
5759

5860
Finally, if you reference any symbols from another framework, and DocC knows how to resolve those, the symbols are fetched and added to the graph too.
5961

60-
### Curation
62+
#### Curation
6163

6264
At this point the in-memory topic graph accurately represents the machine generated description of the documented framework. However, documentation is often better consumed when it's curated into logical groups and into an incremental learning experience.
6365

@@ -102,4 +104,4 @@ The file hierarchy under the output path represents the complete, compiled docum
102104
╰ videos
103105
```
104106

105-
<!-- Copyright (c) 2021 Apple Inc and the Swift Project authors. All Rights Reserved. -->
107+
<!-- Copyright (c) 2021-2024 Apple Inc and the Swift Project authors. All Rights Reserved. -->

Sources/SwiftDocC/SwiftDocC.docc/SwiftDocC/DocumentationContextGroup.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Build and query the in-memory documentation model.
44

55
## Discussion
66

7-
The documentation context generally manages the in-memory documentation including:
8-
7+
A documentation context is the the in-memory representation of a "unit" of documentation (for example a module, package, or technology).
8+
The context is generally responsible for:
9+
910
- Analyzing bundle file contents and converting to semantic models.
1011
- Managing a graph of documentation nodes (a single node representing one documentation topic).
1112
- Processing assets like media files or download archives.
@@ -14,12 +15,17 @@ The documentation context generally manages the in-memory documentation includin
1415

1516
### Creating a Context
1617

18+
Use ``DocumentationContext/init(bundle:dataProvider:diagnosticEngine:configuration:)`` to create a context for a given bundle:
19+
1720
```swift
18-
let workspace = DocumentationWorkspace()
19-
let context = try DocumentationContext(dataProvider: workspace)
20-
```
21+
let inputsProvider = DocumentationContext.InputsProvider()
22+
let (bundle, dataProvider) = try inputsProvider.inputsAndDataProvider(
23+
startingPoint: catalogURL,
24+
options: bundleDiscoveryOptions
25+
)
2126

22-
During initialization the context will inspect the available bundles in the workspace and load any symbol graph files and markup files.
27+
let context = try DocumentationContext(bundle: bundle, dataProvider: dataProvider)
28+
```
2329

2430
### Accessing Documentation
2531

@@ -40,19 +46,11 @@ To find out the location of the source file for a given documentation node use:
4046
let sourceFileURL = try context.documentURL(for: reference)
4147
```
4248

43-
And finally to print all known paths in the context:
44-
45-
```swift
46-
context.knownIdentifiers.forEach({ print($0) })
47-
```
48-
4949
## Topics
5050

5151
### Documentation Context
5252

5353
- ``DocumentationContext``
54-
- ``DocumentationContextDataProvider``
55-
- ``DocumentationContextDataProviderDelegate``
5654
- ``AutomaticCuration``
5755

5856
### Documentation Nodes

0 commit comments

Comments
 (0)