diff --git a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift index f807d9d88f..4904fa6ac4 100644 --- a/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift +++ b/Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift @@ -267,7 +267,7 @@ public struct ConvertService: DocumentationService { .compactMap { (value, isDocumentationExtensionContent) -> (ResolvedTopicReference, RenderReferenceStore.TopicContent)? in let (topicReference, article) = value - guard let bundle = context.bundle(identifier: topicReference.bundleIdentifier) else { return nil } + guard let bundle = context.bundle, bundle.identifier == topicReference.bundleIdentifier else { return nil } let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle) let documentationNodeKind: DocumentationNode.Kind = isDocumentationExtensionContent ? .unknownSymbol : .article diff --git a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift index 1eeebb50ee..92b674717a 100644 --- a/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift +++ b/Sources/SwiftDocC/Infrastructure/DocumentationContext.swift @@ -147,6 +147,7 @@ public class DocumentationContext { } } + /// The documentation bundle that is registered with the context. var bundle: DocumentationBundle? /// A collection of configuration for this context. @@ -362,7 +363,20 @@ public class DocumentationContext { } /// The documentation bundles that are currently registered with the context. + @available(*, deprecated, message: "Use 'bundle' instead. This deprecated API will be removed after 6.2 is released") public var registeredBundles: some Collection { + _registeredBundles + } + + /// Returns the `DocumentationBundle` with the given `identifier` if it's registered with the context, otherwise `nil`. + @available(*, deprecated, message: "Use 'bundle' instead. This deprecated API will be removed after 6.2 is released") + public func bundle(identifier: String) -> DocumentationBundle? { + _bundle(identifier: identifier) + } + + // Remove these when removing `registeredBundles` and `bundle(identifier:)`. + // These exist so that internal code that need to be compatible with legacy data providers can access the bundles without deprecation warnings. + var _registeredBundles: [DocumentationBundle] { switch dataProvider { case .legacy(let legacyDataProvider): Array(legacyDataProvider.bundles.values) @@ -371,8 +385,7 @@ public class DocumentationContext { } } - /// Returns the `DocumentationBundle` with the given `identifier` if it's registered with the context, otherwise `nil`. - public func bundle(identifier: String) -> DocumentationBundle? { + func _bundle(identifier: String) -> DocumentationBundle? { switch dataProvider { case .legacy(let legacyDataProvider): legacyDataProvider.bundles[identifier] @@ -2678,7 +2691,7 @@ public class DocumentationContext { - Throws: ``ContextError/notFound(_:)` if a resource with the given was not found. */ public func resource(with identifier: ResourceReference, trait: DataTraitCollection = .init()) throws -> Data { - guard let bundle = bundle(identifier: identifier.bundleIdentifier), + guard let bundle, let assetManager = assetManagers[identifier.bundleIdentifier], let asset = assetManager.allData(named: identifier.path) else { throw ContextError.notFound(identifier.url) diff --git a/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift b/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift index e2a4c42d4b..4a7c25303c 100644 --- a/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift +++ b/Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver.swift @@ -93,7 +93,7 @@ public class LinkResolver { // Check if this is a link to an external documentation source that should have previously been resolved in `DocumentationContext.preResolveExternalLinks(...)` if let bundleID = unresolvedReference.bundleIdentifier, - !context.registeredBundles.contains(where: { $0.identifier == bundleID || urlReadablePath($0.displayName) == bundleID }) + !context._registeredBundles.contains(where: { $0.identifier == bundleID || urlReadablePath($0.displayName) == bundleID }) { return .failure(unresolvedReference, TopicReferenceResolutionErrorInfo("No external resolver registered for \(bundleID.singleQuoted).")) } @@ -171,7 +171,8 @@ private final class FallbackResolverBasedLinkResolver { // Check if a fallback reference resolver should resolve this let referenceBundleIdentifier = unresolvedReference.bundleIdentifier ?? parent.bundleIdentifier guard let fallbackResolver = context.configuration.convertServiceConfiguration.fallbackResolver, - let knownBundleIdentifier = context.registeredBundles.first(where: { $0.identifier == referenceBundleIdentifier || urlReadablePath($0.displayName) == referenceBundleIdentifier })?.identifier, + // This uses an underscored internal variant of `registeredBundles` to avoid deprecation warnings and remain compatible with legacy data providers. + let knownBundleIdentifier = context._registeredBundles.first(where: { $0.identifier == referenceBundleIdentifier || urlReadablePath($0.displayName) == referenceBundleIdentifier })?.identifier, fallbackResolver.bundleIdentifier == knownBundleIdentifier else { return nil @@ -190,7 +191,8 @@ private final class FallbackResolverBasedLinkResolver { ) allCandidateURLs.append(alreadyResolved.url) - let currentBundle = context.bundle(identifier: knownBundleIdentifier)! + // This uses an underscored internal variant of `bundle(identifier:)` to avoid deprecation warnings and remain compatible with legacy data providers. + let currentBundle = context._bundle(identifier: knownBundleIdentifier)! if !isCurrentlyResolvingSymbolLink { // First look up articles path allCandidateURLs.append(contentsOf: [ diff --git a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift index b8ab3892df..9a9fa77f74 100644 --- a/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift +++ b/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift @@ -311,7 +311,7 @@ public extension DocumentationNode { renderNode: RenderNode, includeTaskGroups: Bool = true ) -> [LinkDestinationSummary] { - guard let bundle = context.bundle(identifier: reference.bundleIdentifier) else { + guard let bundle = context.bundle, bundle.identifier == reference.bundleIdentifier else { // Don't return anything for external references that don't have a bundle in the context. return [] } diff --git a/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift b/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift index 7db36ede7e..690d985589 100644 --- a/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift +++ b/Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift @@ -27,7 +27,7 @@ struct LinkTitleResolver { /// - Parameter page: The page for which to resolve the title. /// - Returns: The variants of the link title for this page, or `nil` if the page doesn't exist in the context. func title(for page: DocumentationNode) -> DocumentationDataVariants? { - if let bundle = context.bundle(identifier: page.reference.bundleIdentifier), + if let bundle = context.bundle, let directive = page.markup.child(at: 0) as? BlockDirective { var problems = [Problem]() diff --git a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift index 3e5dce40fc..bbcacadef7 100644 --- a/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift +++ b/Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift @@ -3233,7 +3233,7 @@ let expected = """ ]) // Verify that the links are resolved in the render model. - let bundle = try XCTUnwrap(context.registeredBundles.first) + let bundle = try XCTUnwrap(context.bundle) let converter = DocumentationNodeConverter(bundle: bundle, context: context) let renderNode = try converter.convert(entity) diff --git a/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift b/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift index 571fb02ed7..9830a83217 100644 --- a/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift +++ b/Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift @@ -2851,8 +2851,7 @@ class ConvertActionTests: XCTestCase { ) let (_, context) = try await action.perform(logHandle: .none) - XCTAssertEqual(context.registeredBundles.count, 1) - let bundle = try XCTUnwrap(context.registeredBundles.first, "Should have registered the generated test bundle.") + let bundle = try XCTUnwrap(context.bundle, "Should have registered the generated test bundle.") XCTAssertEqual(bundle.displayName, "MyKit") XCTAssertEqual(bundle.identifier, "MyKit") } @@ -2930,8 +2929,7 @@ class ConvertActionTests: XCTestCase { ) let (_, context) = try await action.perform(logHandle: .none) - XCTAssertEqual(context.registeredBundles.count, 1) - let bundle = try XCTUnwrap(context.registeredBundles.first, "Should have registered the generated test bundle.") + let bundle = try XCTUnwrap(context.bundle, "Should have registered the generated test bundle.") XCTAssertEqual(bundle.displayName, "Something") XCTAssertEqual(bundle.identifier, "com.example.test") }