Skip to content

Commit 45a91aa

Browse files
committed
Deprecate additional multi-bundle-related properties
1 parent 8714446 commit 45a91aa

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public struct ConvertService: DocumentationService {
267267
.compactMap { (value, isDocumentationExtensionContent) -> (ResolvedTopicReference, RenderReferenceStore.TopicContent)? in
268268
let (topicReference, article) = value
269269

270-
guard let bundle = context.bundle(identifier: topicReference.bundleIdentifier) else { return nil }
270+
guard let bundle = context.bundle, bundle.identifier == topicReference.bundleIdentifier else { return nil }
271271
let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle)
272272

273273
let documentationNodeKind: DocumentationNode.Kind = isDocumentationExtensionContent ? .unknownSymbol : .article

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public class DocumentationContext {
147147
}
148148
}
149149

150+
/// The documentation bundle that is registered with the context.
150151
var bundle: DocumentationBundle?
151152

152153
/// A collection of configuration for this context.
@@ -362,7 +363,20 @@ public class DocumentationContext {
362363
}
363364

364365
/// The documentation bundles that are currently registered with the context.
366+
@available(*, deprecated, message: "Use 'bundle' instead. This deprecated API will be removed after 6.2 is released")
365367
public var registeredBundles: some Collection<DocumentationBundle> {
368+
_registeredBundles
369+
}
370+
371+
/// Returns the `DocumentationBundle` with the given `identifier` if it's registered with the context, otherwise `nil`.
372+
@available(*, deprecated, message: "Use 'bundle' instead. This deprecated API will be removed after 6.2 is released")
373+
public func bundle(identifier: String) -> DocumentationBundle? {
374+
_bundle(identifier: identifier)
375+
}
376+
377+
// Remove these when removing `registeredBundles` and `bundle(identifier:)`.
378+
// These exist so that internal code that need to be compatible with legacy data providers can access the bundles without deprecation warnings.
379+
var _registeredBundles: [DocumentationBundle] {
366380
switch dataProvider {
367381
case .legacy(let legacyDataProvider):
368382
Array(legacyDataProvider.bundles.values)
@@ -371,8 +385,7 @@ public class DocumentationContext {
371385
}
372386
}
373387

374-
/// Returns the `DocumentationBundle` with the given `identifier` if it's registered with the context, otherwise `nil`.
375-
public func bundle(identifier: String) -> DocumentationBundle? {
388+
func _bundle(identifier: String) -> DocumentationBundle? {
376389
switch dataProvider {
377390
case .legacy(let legacyDataProvider):
378391
legacyDataProvider.bundles[identifier]
@@ -2678,7 +2691,7 @@ public class DocumentationContext {
26782691
- Throws: ``ContextError/notFound(_:)` if a resource with the given was not found.
26792692
*/
26802693
public func resource(with identifier: ResourceReference, trait: DataTraitCollection = .init()) throws -> Data {
2681-
guard let bundle = bundle(identifier: identifier.bundleIdentifier),
2694+
guard let bundle,
26822695
let assetManager = assetManagers[identifier.bundleIdentifier],
26832696
let asset = assetManager.allData(named: identifier.path) else {
26842697
throw ContextError.notFound(identifier.url)

Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class LinkResolver {
9393

9494
// Check if this is a link to an external documentation source that should have previously been resolved in `DocumentationContext.preResolveExternalLinks(...)`
9595
if let bundleID = unresolvedReference.bundleIdentifier,
96-
!context.registeredBundles.contains(where: { $0.identifier == bundleID || urlReadablePath($0.displayName) == bundleID })
96+
!context._registeredBundles.contains(where: { $0.identifier == bundleID || urlReadablePath($0.displayName) == bundleID })
9797
{
9898
return .failure(unresolvedReference, TopicReferenceResolutionErrorInfo("No external resolver registered for \(bundleID.singleQuoted)."))
9999
}
@@ -171,7 +171,8 @@ private final class FallbackResolverBasedLinkResolver {
171171
// Check if a fallback reference resolver should resolve this
172172
let referenceBundleIdentifier = unresolvedReference.bundleIdentifier ?? parent.bundleIdentifier
173173
guard let fallbackResolver = context.configuration.convertServiceConfiguration.fallbackResolver,
174-
let knownBundleIdentifier = context.registeredBundles.first(where: { $0.identifier == referenceBundleIdentifier || urlReadablePath($0.displayName) == referenceBundleIdentifier })?.identifier,
174+
// This uses an underscored internal variant of `registeredBundles` to avoid deprecation warnings and remain compatible with legacy data providers.
175+
let knownBundleIdentifier = context._registeredBundles.first(where: { $0.identifier == referenceBundleIdentifier || urlReadablePath($0.displayName) == referenceBundleIdentifier })?.identifier,
175176
fallbackResolver.bundleIdentifier == knownBundleIdentifier
176177
else {
177178
return nil
@@ -190,7 +191,8 @@ private final class FallbackResolverBasedLinkResolver {
190191
)
191192
allCandidateURLs.append(alreadyResolved.url)
192193

193-
let currentBundle = context.bundle(identifier: knownBundleIdentifier)!
194+
// This uses an underscored internal variant of `bundle(identifier:)` to avoid deprecation warnings and remain compatible with legacy data providers.
195+
let currentBundle = context._bundle(identifier: knownBundleIdentifier)!
194196
if !isCurrentlyResolvingSymbolLink {
195197
// First look up articles path
196198
allCandidateURLs.append(contentsOf: [

Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public extension DocumentationNode {
311311
renderNode: RenderNode,
312312
includeTaskGroups: Bool = true
313313
) -> [LinkDestinationSummary] {
314-
guard let bundle = context.bundle(identifier: reference.bundleIdentifier) else {
314+
guard let bundle = context.bundle, bundle.identifier == reference.bundleIdentifier else {
315315
// Don't return anything for external references that don't have a bundle in the context.
316316
return []
317317
}

Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct LinkTitleResolver {
2727
/// - Parameter page: The page for which to resolve the title.
2828
/// - Returns: The variants of the link title for this page, or `nil` if the page doesn't exist in the context.
2929
func title(for page: DocumentationNode) -> DocumentationDataVariants<String>? {
30-
if let bundle = context.bundle(identifier: page.reference.bundleIdentifier),
30+
if let bundle = context.bundle,
3131
let directive = page.markup.child(at: 0) as? BlockDirective {
3232

3333
var problems = [Problem]()

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ let expected = """
32333233
])
32343234

32353235
// Verify that the links are resolved in the render model.
3236-
let bundle = try XCTUnwrap(context.registeredBundles.first)
3236+
let bundle = try XCTUnwrap(context.bundle)
32373237
let converter = DocumentationNodeConverter(bundle: bundle, context: context)
32383238
let renderNode = try converter.convert(entity)
32393239

Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,8 +2851,7 @@ class ConvertActionTests: XCTestCase {
28512851
)
28522852
let (_, context) = try await action.perform(logHandle: .none)
28532853

2854-
XCTAssertEqual(context.registeredBundles.count, 1)
2855-
let bundle = try XCTUnwrap(context.registeredBundles.first, "Should have registered the generated test bundle.")
2854+
let bundle = try XCTUnwrap(context.bundle, "Should have registered the generated test bundle.")
28562855
XCTAssertEqual(bundle.displayName, "MyKit")
28572856
XCTAssertEqual(bundle.identifier, "MyKit")
28582857
}
@@ -2930,8 +2929,7 @@ class ConvertActionTests: XCTestCase {
29302929
)
29312930
let (_, context) = try await action.perform(logHandle: .none)
29322931

2933-
XCTAssertEqual(context.registeredBundles.count, 1)
2934-
let bundle = try XCTUnwrap(context.registeredBundles.first, "Should have registered the generated test bundle.")
2932+
let bundle = try XCTUnwrap(context.bundle, "Should have registered the generated test bundle.")
29352933
XCTAssertEqual(bundle.displayName, "Something")
29362934
XCTAssertEqual(bundle.identifier, "com.example.test")
29372935
}

0 commit comments

Comments
 (0)