Skip to content

Commit eb5ba13

Browse files
authored
Remove redundant "bundle" parameters where a context is also available (#1309)
* Rename context "bundle" property to "inputs" * Remove redundant "bundle" parameter from RenderHierarchyTranslator * Remove redundant "bundle" parameter from RenderContentCompiler * Update test to avoid using inputs that don't belong to the context * Remove redundant "bundle" parameter from MarkupReferenceResolver * Remove redundant "bundle" parameter from ReferenceResolver * Remove redundant "bundle" parameter from DocumentationContentRenderer * Remove redundant "bundle" parameter from RenderNodeTranslator * Remove redundant "bundle" parameter from DocumentationNodeConverter * Remove redundant "bundle" parameter from DocumentationContextConverter * Remove redundant "bundle" parameter from GeneratedDocumentationTopics * Remove redundant "bundle" parameter from ConvertActionConverter * Remove redundant "bundle" parameter from AutomaticCuration.seeAlso * Remove redundant "bundle" parameter from RenderNodeTranslator.defaultAvailability * Remove redundant "bundle" parameter from DocumentationCurator * Remove unused DocumentationContext.unregister method * Remove redundant "bundle" parameter from PathHierarchyBasedLinkResolver.referencesForSymbols * Remove redundant "bundle" parameters from various private DocumentationContext methods * Remove two local "bundle" variables
1 parent c5f99a2 commit eb5ba13

File tree

87 files changed

+1089
-1248
lines changed

Some content is hidden

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

87 files changed

+1089
-1248
lines changed

Sources/SwiftDocC/Converter/DocumentationContextConverter.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public class DocumentationContextConverter {
2020
/// The context the converter uses to resolve references it finds in the documentation node's content.
2121
let context: DocumentationContext
2222

23-
/// The bundle that contains the content from which the documentation node originated.
24-
let bundle: DocumentationBundle
25-
2623
/// A context that contains common pre-rendered pieces of content.
2724
let renderContext: RenderContext
2825

@@ -43,12 +40,11 @@ public class DocumentationContextConverter {
4340
/// The remote source control repository where the documented module's source is hosted.
4441
let sourceRepository: SourceRepository?
4542

46-
/// Creates a new node converter for the given bundle and context.
43+
/// Creates a new node converter for the given context.
4744
///
4845
/// The converter uses bundle and context to resolve references to other documentation and describe the documentation hierarchy.
4946
///
5047
/// - Parameters:
51-
/// - bundle: The bundle that contains the content from which the documentation node originated.
5248
/// - context: The context that the converter uses to to resolve references it finds in the documentation node's content.
5349
/// - renderContext: A context that contains common pre-rendered pieces of content.
5450
/// - emitSymbolSourceFileURIs: Whether the documentation converter should include
@@ -61,22 +57,39 @@ public class DocumentationContextConverter {
6157
/// - sourceRepository: The source repository where the documentation's sources are hosted.
6258
/// - symbolIdentifiersWithExpandedDocumentation: A list of symbol IDs that have version of their documentation page with more content that a renderer can link to.
6359
public init(
64-
bundle: DocumentationBundle,
6560
context: DocumentationContext,
6661
renderContext: RenderContext,
6762
emitSymbolSourceFileURIs: Bool = false,
6863
emitSymbolAccessLevels: Bool = false,
6964
sourceRepository: SourceRepository? = nil,
7065
symbolIdentifiersWithExpandedDocumentation: [String]? = nil
7166
) {
72-
self.bundle = bundle
7367
self.context = context
7468
self.renderContext = renderContext
7569
self.shouldEmitSymbolSourceFileURIs = emitSymbolSourceFileURIs
7670
self.shouldEmitSymbolAccessLevels = emitSymbolAccessLevels
7771
self.sourceRepository = sourceRepository
7872
self.symbolIdentifiersWithExpandedDocumentation = symbolIdentifiersWithExpandedDocumentation
7973
}
74+
@available(*, deprecated, renamed: "init(context:renderContext:emitSymbolSourceFileURIs:emitSymbolAccessLevels:sourceRepository:symbolIdentifiersWithExpandedDocumentation:)", message: "Use 'init(context:renderContext:emitSymbolSourceFileURIs:emitSymbolAccessLevels:sourceRepository:symbolIdentifiersWithExpandedDocumentation:)' instead. This deprecated API will be removed after 6.4 is released.")
75+
public convenience init(
76+
bundle _: DocumentationBundle,
77+
context: DocumentationContext,
78+
renderContext: RenderContext,
79+
emitSymbolSourceFileURIs: Bool = false,
80+
emitSymbolAccessLevels: Bool = false,
81+
sourceRepository: SourceRepository? = nil,
82+
symbolIdentifiersWithExpandedDocumentation: [String]? = nil
83+
) {
84+
self.init(
85+
context: context,
86+
renderContext: renderContext,
87+
emitSymbolSourceFileURIs: emitSymbolSourceFileURIs,
88+
emitSymbolAccessLevels: emitSymbolAccessLevels,
89+
sourceRepository: sourceRepository,
90+
symbolIdentifiersWithExpandedDocumentation: symbolIdentifiersWithExpandedDocumentation
91+
)
92+
}
8093

8194
/// Converts a documentation node to a render node.
8295
///
@@ -91,7 +104,6 @@ public class DocumentationContextConverter {
91104

92105
var translator = RenderNodeTranslator(
93106
context: context,
94-
bundle: bundle,
95107
identifier: node.reference,
96108
renderContext: renderContext,
97109
emitSymbolSourceFileURIs: shouldEmitSymbolSourceFileURIs,

Sources/SwiftDocC/Converter/DocumentationNodeConverter.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ public struct DocumentationNodeConverter {
1515
/// The context the converter uses to resolve references it finds in the documentation node's content.
1616
let context: DocumentationContext
1717

18-
/// The bundle that contains the content from which the documentation node originated.
19-
let bundle: DocumentationBundle
20-
21-
/// Creates a new node converter for the given bundle and context.
18+
/// Creates a new node converter for the given context.
2219
///
23-
/// The converter uses bundle and context to resolve references to other documentation and describe the documentation hierarchy.
20+
/// The converter uses context to resolve references to other documentation and describe the documentation hierarchy.
2421
///
2522
/// - Parameters:
26-
/// - bundle: The bundle that contains the content from which the documentation node originated.
2723
/// - context: The context that the converter uses to to resolve references it finds in the documentation node's content.
28-
public init(bundle: DocumentationBundle, context: DocumentationContext) {
29-
self.bundle = bundle
24+
public init(context: DocumentationContext) {
3025
self.context = context
3126
}
27+
@available(*, deprecated, renamed: "init(context:)", message: "Use 'init(context:)' instead. This deprecated API will be removed after 6.4 is released.")
28+
public init(bundle _: DocumentationBundle, context: DocumentationContext) {
29+
self.init(context: context)
30+
}
3231

3332
/// Converts a documentation node to a render node.
3433
///
@@ -37,7 +36,7 @@ public struct DocumentationNodeConverter {
3736
/// - node: The documentation node to convert.
3837
/// - Returns: The render node representation of the documentation node.
3938
public func convert(_ node: DocumentationNode) -> RenderNode {
40-
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference)
39+
var translator = RenderNodeTranslator(context: context, identifier: node.reference)
4140
return translator.visit(node.semantic) as! RenderNode
4241
}
4342
}

Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public struct ConvertService: DocumentationService {
158158
let context = try await DocumentationContext(bundle: bundle, dataProvider: dataProvider, configuration: configuration)
159159

160160
// Precompute the render context
161-
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
161+
let renderContext = RenderContext(documentationContext: context)
162162

163163
let symbolIdentifiersMeetingRequirementsForExpandedDocumentation: [String]? = request.symbolIdentifiersWithExpandedDocumentation?.compactMap { identifier, expandedDocsRequirement in
164164
guard let documentationNode = context.documentationCache[identifier] else {
@@ -168,7 +168,6 @@ public struct ConvertService: DocumentationService {
168168
return documentationNode.meetsExpandedDocumentationRequirements(expandedDocsRequirement) ? identifier : nil
169169
}
170170
let converter = DocumentationContextConverter(
171-
bundle: bundle,
172171
context: context,
173172
renderContext: renderContext,
174173
emitSymbolSourceFileURIs: request.emitSymbolSourceFileURIs,
@@ -243,12 +242,11 @@ public struct ConvertService: DocumentationService {
243242
.compactMap { (value, isDocumentationExtensionContent) -> (ResolvedTopicReference, RenderReferenceStore.TopicContent)? in
244243
let (topicReference, article) = value
245244

246-
let bundle = context.bundle
247-
guard bundle.id == topicReference.bundleID else { return nil }
248-
let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle)
245+
guard context.inputs.id == topicReference.bundleID else { return nil }
246+
let renderer = DocumentationContentRenderer(context: context)
249247

250248
let documentationNodeKind: DocumentationNode.Kind = isDocumentationExtensionContent ? .unknownSymbol : .article
251-
let overridingDocumentationNode = DocumentationContext.documentationNodeAndTitle(for: article, kind: documentationNodeKind, in: bundle)?.node
249+
let overridingDocumentationNode = DocumentationContext.documentationNodeAndTitle(for: article, kind: documentationNodeKind, in: context.inputs)?.node
252250
var dependencies = RenderReferenceDependencies()
253251
let renderReference = renderer.renderReference(for: topicReference, with: overridingDocumentationNode, dependencies: &dependencies)
254252

Sources/SwiftDocC/Infrastructure/ConvertActionConverter.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ package enum ConvertActionConverter {
2121
static package let signposter = NoOpSignposterShim()
2222
#endif
2323

24-
/// Converts the documentation bundle in the given context and passes its output to a given consumer.
24+
/// Converts the documentation in the given context and passes its output to a given consumer.
2525
///
2626
/// - Parameters:
27-
/// - bundle: The documentation bundle to convert.
2827
/// - context: The context that the bundle is a part of.
2928
/// - outputConsumer: The consumer that the conversion passes outputs of the conversion to.
3029
/// - sourceRepository: The source repository where the documentation's sources are hosted.
3130
/// - emitDigest: Whether the conversion should pass additional metadata output––such as linkable entities information, indexing information, or asset references by asset type––to the consumer.
3231
/// - documentationCoverageOptions: The level of experimental documentation coverage information that the conversion should pass to the consumer.
3332
/// - Returns: A list of problems that occurred during the conversion (excluding the problems that the context already encountered).
3433
package static func convert(
35-
bundle: DocumentationBundle,
3634
context: DocumentationContext,
3735
outputConsumer: some ConvertOutputConsumer & ExternalNodeConsumer,
3836
sourceRepository: SourceRepository?,
@@ -61,15 +59,14 @@ package enum ConvertActionConverter {
6159

6260
// Precompute the render context
6361
let renderContext = signposter.withIntervalSignpost("Build RenderContext", id: signposter.makeSignpostID()) {
64-
RenderContext(documentationContext: context, bundle: bundle)
62+
RenderContext(documentationContext: context)
6563
}
6664
try outputConsumer.consume(renderReferenceStore: renderContext.store)
6765

6866
// Copy images, sample files, and other static assets.
69-
try outputConsumer.consume(assetsInBundle: bundle)
67+
try outputConsumer.consume(assetsInBundle: context.inputs)
7068

7169
let converter = DocumentationContextConverter(
72-
bundle: bundle,
7370
context: context,
7471
renderContext: renderContext,
7572
sourceRepository: sourceRepository
@@ -109,7 +106,7 @@ package enum ConvertActionConverter {
109106
// Here we're associating the external node with the **current** bundle's bundle ID.
110107
// This is needed because nodes are only considered children if the parent and child's bundle ID match.
111108
// Otherwise, the node will be considered as a separate root node and displayed separately.
112-
let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: bundle.id)
109+
let externalRenderNode = ExternalRenderNode(externalEntity: externalLink.value, bundleIdentifier: context.inputs.id)
113110
try outputConsumer.consume(externalRenderNode: externalRenderNode)
114111
}
115112

@@ -192,7 +189,7 @@ package enum ConvertActionConverter {
192189
if FeatureFlags.current.isExperimentalLinkHierarchySerializationEnabled {
193190
signposter.withIntervalSignpost("Serialize link hierarchy", id: signposter.makeSignpostID()) {
194191
do {
195-
let serializableLinkInformation = try context.linkResolver.localResolver.prepareForSerialization(bundleID: bundle.id)
192+
let serializableLinkInformation = try context.linkResolver.localResolver.prepareForSerialization(bundleID: context.inputs.id)
196193
try outputConsumer.consume(linkResolutionInformation: serializableLinkInformation)
197194

198195
if !emitDigest {
@@ -225,7 +222,7 @@ package enum ConvertActionConverter {
225222
break
226223
}
227224

228-
try outputConsumer.consume(buildMetadata: BuildMetadata(bundleDisplayName: bundle.displayName, bundleID: bundle.id))
225+
try outputConsumer.consume(buildMetadata: BuildMetadata(bundleDisplayName: context.inputs.displayName, bundleID: context.inputs.id))
229226

230227
// Log the finalized topic graph checksum.
231228
benchmark(add: Benchmark.TopicGraphHash(context: context))

0 commit comments

Comments
 (0)