Skip to content

Commit

Permalink
Deprecate additional multi-bundle-related properties
Browse files Browse the repository at this point in the history
  • Loading branch information
d-ronnqvist committed Oct 21, 2024
1 parent 8714446 commit 45a91aa
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions Sources/SwiftDocC/Infrastructure/DocumentationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<DocumentationBundle> {
_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)
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)."))
}
Expand Down Expand Up @@ -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
Expand All @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDocC/Model/Rendering/LinkTitleResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? {
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]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 45a91aa

Please sign in to comment.