Skip to content

Commit e06e798

Browse files
Autogenerate directive documentation based on models in SwiftDocC framework (#447)
* Fix existing broken documentation Merging the SwiftDocC’s conceptual documentation into the `docc` executable documentation broke documentation building in some ways when building in Xcode. This just resolves the existing issues. * Mark all existing documentation extensions as overriding Prepares for adding documentation comment to the autogenerated symbol graph by marking existing documentation extensions as overriding. Eventually we can merge some of this documentation back into the source. * Autogenerate directive documentation Autogenerate documentation for directives based on what is defined in SwiftDocC framework source. rdar://103925835
1 parent 496639f commit e06e798

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4423
-481
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ let package = Package(
100100
.executableTarget(
101101
name: "generate-symbol-graph",
102102
dependencies: [
103+
"SwiftDocC",
103104
"SymbolKit",
104105
]
105106
),

Sources/SwiftDocC/Semantics/DirectiveInfrastructure/AutomaticDirectiveConvertible.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ protocol AutomaticDirectiveConvertible: DirectiveConvertible, Semantic {
7070
/// }
7171
/// }
7272
static var keyPaths: [String : AnyKeyPath] { get }
73+
74+
/// A Boolean value that is true if this directive should be hidden from documentation.
75+
static var hiddenFromDocumentation: Bool { get }
7376
}
7477

7578
extension AutomaticDirectiveConvertible {
@@ -85,6 +88,8 @@ extension AutomaticDirectiveConvertible {
8588
) -> Bool {
8689
return true
8790
}
91+
92+
public static var hiddenFromDocumentation: Bool { false }
8893
}
8994

9095
extension AutomaticDirectiveConvertible {
@@ -234,7 +239,7 @@ extension AutomaticDirectiveConvertible {
234239

235240
guard let parsedDirective = parsedDirective else {
236241
if childDirective.storedAsArray && !childDirective.storedAsOptional {
237-
childDirective.setValue(on: self, to: [])
242+
childDirective.setValue(on: self, to: [parsedDirective].compactMap { $0 })
238243
}
239244

240245
continue

Sources/SwiftDocC/Semantics/DirectiveInfrastructure/DirectiveArgumentWrapper.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public struct DirectiveArgumentWrapped<Value>: _DirectiveArgumentProtocol {
9898
) {
9999
self.name = name
100100
self.defaultValue = value
101-
if let optionallyWrappedValue = Value.self as? OptionallyWrapped {
102-
self.typeDisplayName = String(describing: optionallyWrappedValue.baseType())
101+
if let optionallyWrappedValue = Value.self as? OptionallyWrapped.Type {
102+
self.typeDisplayName = String(describing: optionallyWrappedValue.baseType()) + "?"
103103
} else {
104104
self.typeDisplayName = String(describing: Value.self)
105105
}
@@ -176,7 +176,13 @@ extension DirectiveArgumentWrapped where Value: DirectiveArgumentValueConvertibl
176176
) {
177177
self.name = name
178178
self.defaultValue = value
179-
self.typeDisplayName = String(describing: Value.self)
179+
180+
if let value = value {
181+
self.typeDisplayName = String(describing: Value.self) + " = " + String(describing: value)
182+
} else {
183+
self.typeDisplayName = String(describing: Value.self)
184+
}
185+
180186
self.parseArgument = { _, argument in
181187
Value.init(rawDirectiveArgumentValue: argument)
182188
}
@@ -197,7 +203,12 @@ extension DirectiveArgumentWrapped where Value: OptionallyWrappedDirectiveArgume
197203

198204
self.name = name
199205
self.defaultValue = wrappedValue
200-
self.typeDisplayName = String(describing: argumentValueType)
206+
if required {
207+
self.typeDisplayName = String(describing: argumentValueType)
208+
} else {
209+
self.typeDisplayName = String(describing: argumentValueType) + "?"
210+
}
211+
201212
self.parseArgument = { _, argument in
202213
argumentValueType.init(rawDirectiveArgumentValue: argument)
203214
}

Sources/SwiftDocC/Semantics/DirectiveInfrastructure/DirectiveIndex.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Foundation
1212

1313
struct DirectiveIndex {
14-
private static let topLevelReferenceDirectives: [AutomaticDirectiveConvertible.Type] = [
14+
static let topLevelReferenceDirectives: [AutomaticDirectiveConvertible.Type] = [
1515
Metadata.self,
1616
Redirect.self,
1717
Snippet.self,
@@ -25,7 +25,7 @@ struct DirectiveIndex {
2525
VideoMedia.self,
2626
]
2727

28-
private static let topLevelTutorialDirectives: [AutomaticDirectiveConvertible.Type] = [
28+
static let topLevelTutorialDirectives: [AutomaticDirectiveConvertible.Type] = [
2929
Tutorial.self,
3030
]
3131

Sources/SwiftDocC/Semantics/DirectiveInfrastructure/DirectiveMirror.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ extension DirectiveMirror {
200200
return type.directiveName
201201
}
202202

203+
var required: Bool {
204+
return requirements == .one || requirements == .oneOrMore
205+
}
206+
203207
let propertyLabel: String
204208
let childDirective: _ChildDirectiveProtocol
205209

@@ -258,6 +262,10 @@ extension DirectiveMirror {
258262
}
259263
}
260264

265+
var hiddenFromDocumentation: Bool {
266+
(type as? AutomaticDirectiveConvertible.Type)?.hiddenFromDocumentation ?? false
267+
}
268+
261269
let type: DirectiveConvertible.Type
262270
}
263271

Sources/SwiftDocC/Semantics/Media/ImageMedia.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public final class ImageMedia: Semantic, Media, AutomaticDirectiveConvertible {
1717

1818
public let originalMarkup: BlockDirective
1919

20+
@DirectiveArgumentWrapped(
21+
parseArgument: { bundle, argumentValue in
22+
ResourceReference(bundleIdentifier: bundle.identifier, path: argumentValue)
23+
}
24+
)
25+
public private(set) var source: ResourceReference
26+
2027
/// Optional alternate text for an image.
2128
@DirectiveArgumentWrapped(name: .custom("alt"))
2229
public private(set) var altText: String? = nil
@@ -25,13 +32,6 @@ public final class ImageMedia: Semantic, Media, AutomaticDirectiveConvertible {
2532
@ChildMarkup(numberOfParagraphs: .zeroOrOne)
2633
public private(set) var caption: MarkupContainer
2734

28-
@DirectiveArgumentWrapped(
29-
parseArgument: { bundle, argumentValue in
30-
ResourceReference(bundleIdentifier: bundle.identifier, path: argumentValue)
31-
}
32-
)
33-
public private(set) var source: ResourceReference
34-
3535
static var keyPaths: [String : AnyKeyPath] = [
3636
"altText" : \ImageMedia._altText,
3737
"source" : \ImageMedia._source,

Sources/SwiftDocC/Semantics/Metadata/CallToAction.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public final class CallToAction: Semantic, AutomaticDirectiveConvertible {
6565
@DirectiveArgumentWrapped
6666
public var purpose: Purpose? = nil
6767

68-
/// Text to use as the button label, which may override ``purpose-swift.property``.
68+
/// Text to use as the button label, which may override the default provided by a
69+
/// given `purpose`.
6970
@DirectiveArgumentWrapped
7071
public var label: String? = nil
7172

Sources/SwiftDocC/Semantics/Metadata/CustomMetadata.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public final class CustomMetadata: Semantic, AutomaticDirectiveConvertible {
3535
@DirectiveArgumentWrapped
3636
public var value: String
3737

38+
static var hiddenFromDocumentation = true
39+
3840
static var keyPaths: [String : AnyKeyPath] = [
3941
"key" : \CustomMetadata._key,
4042
"value" : \CustomMetadata._value,

Sources/SwiftDocC/Semantics/Options/Options.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@
1111
import Foundation
1212
import Markdown
1313

14-
/// A directive that specifies various options for the page.
14+
/// Use Option directives to adjust DocC's default behaviors when rendering a page.
15+
///
16+
/// ## Topics
17+
///
18+
/// ### Adjusting Automatic Behaviors
19+
///
20+
/// - ``AutomaticSeeAlso``
21+
/// - ``AutomaticTitleHeading``
22+
/// - ``AutomaticArticleSubheading``
23+
///
24+
/// ### Adjusting Visual Style
25+
///
26+
/// - ``TopicsVisualStyle``
1527
public class Options: Semantic, AutomaticDirectiveConvertible {
1628
public let originalMarkup: BlockDirective
1729

Sources/SwiftDocC/Semantics/Redirect.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class Redirect: Semantic, AutomaticDirectiveConvertible {
3030
"oldPath" : \Redirect._oldPath,
3131
]
3232

33+
static var hiddenFromDocumentation = true
34+
3335
init(originalMarkup: BlockDirective, oldPath: URL) {
3436
self.originalMarkup = originalMarkup
3537
super.init()

0 commit comments

Comments
 (0)