Skip to content

Commit

Permalink
Prefer bundleID over id for types that scoped inside bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
d-ronnqvist committed Oct 24, 2024
1 parent e3faaf2 commit f86a125
Show file tree
Hide file tree
Showing 94 changed files with 578 additions and 582 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, bundle.id == topicReference.id else { return nil }
guard let bundle = context.bundle, bundle.id == topicReference.bundleID else { return nil }
let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle)

let documentationNodeKind: DocumentationNode.Kind = isDocumentationExtensionContent ? .unknownSymbol : .article
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ extension ResolvedTopicReference {
let normalizedPath = NodeURLGenerator.fileSafeReferencePath(self, lowercased: true)

return NavigatorIndex.Identifier(
bundleIdentifier: id.rawValue.lowercased(),
bundleIdentifier: bundleID.rawValue.lowercased(),
path: "/" + normalizedPath,
fragment: fragment,
languageIdentifier: languageIdentifier
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftDocC/Infrastructure/DocumentationBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public struct DocumentationBundle {
self.customHeader = customHeader
self.customFooter = customFooter
self.themeSettings = themeSettings
self.rootReference = ResolvedTopicReference(id: info.id, path: "/", sourceLanguage: .swift)
self.documentationRootReference = ResolvedTopicReference(id: info.id, path: NodeURLGenerator.Path.documentationFolder, sourceLanguage: .swift)
self.tutorialTableOfContentsContainer = ResolvedTopicReference(id: info.id, path: NodeURLGenerator.Path.tutorialsFolder, sourceLanguage: .swift)
self.rootReference = ResolvedTopicReference(bundleID: info.id, path: "/", sourceLanguage: .swift)
self.documentationRootReference = ResolvedTopicReference(bundleID: info.id, path: NodeURLGenerator.Path.documentationFolder, sourceLanguage: .swift)
self.tutorialTableOfContentsContainer = ResolvedTopicReference(bundleID: info.id, path: NodeURLGenerator.Path.tutorialsFolder, sourceLanguage: .swift)
self.tutorialsContainerReference = tutorialTableOfContentsContainer.appendingPath(urlReadablePath(info.displayName))
self.articlesDocumentationRootReference = documentationRootReference.appendingPath(urlReadablePath(info.displayName))
}
Expand Down
24 changes: 12 additions & 12 deletions Sources/SwiftDocC/Infrastructure/DocumentationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ public class DocumentationContext {
let (url, analyzed) = analyzedDocument

let path = NodeURLGenerator.pathForSemantic(analyzed, source: url, bundle: bundle)
let reference = ResolvedTopicReference(id: bundle.id, path: path, sourceLanguage: .swift)
let reference = ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguage: .swift)

// Since documentation extensions' filenames have no impact on the URL of pages, there is no need to enforce unique filenames for them.
// At this point we consider all articles with an H1 containing link a "documentation extension."
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public class DocumentationContext {

let symbolPath = NodeURLGenerator.Path.documentation(path: url.components.path).stringValue
let symbolReference = ResolvedTopicReference(
id: reference.id,
bundleID: reference.bundleID,
path: symbolPath,
fragment: nil,
sourceLanguages: reference.sourceLanguages
Expand Down Expand Up @@ -1948,7 +1948,7 @@ public class DocumentationContext {
let title = articleResult.source.deletingPathExtension().lastPathComponent
// Create a new root-looking reference
let reference = ResolvedTopicReference(
id: bundle.id,
bundleID: bundle.id,
path: NodeURLGenerator.Path.documentation(path: title).stringValue,
sourceLanguages: [DocumentationContext.defaultLanguage(in: nil /* article-only content has no source language information */)]
)
Expand Down Expand Up @@ -1987,7 +1987,7 @@ public class DocumentationContext {
let path = NodeURLGenerator.Path.documentation(path: title).stringValue
let sourceLanguage = DocumentationContext.defaultLanguage(in: [])

let reference = ResolvedTopicReference(id: bundle.id, path: path, sourceLanguages: [sourceLanguage])
let reference = ResolvedTopicReference(bundleID: bundle.id, path: path, sourceLanguages: [sourceLanguage])

let graphNode = TopicGraph.Node(reference: reference, kind: .module, source: .external, title: title)
topicGraph.addNode(graphNode)
Expand Down Expand Up @@ -2052,7 +2052,7 @@ public class DocumentationContext {
let defaultSourceLanguage = defaultLanguage(in: availableSourceLanguages)

let reference = ResolvedTopicReference(
id: bundle.id,
bundleID: bundle.id,
path: path,
sourceLanguages: availableSourceLanguages
// FIXME: Pages in article-only catalogs should not be inferred as "Swift" as a fallback
Expand Down Expand Up @@ -2687,12 +2687,12 @@ public class DocumentationContext {
*/
private func unregister(_ bundle: DocumentationBundle) {
let referencesToRemove = topicGraph.nodes.keys.filter {
$0.id == bundle.id
$0.bundleID == bundle.id
}

for reference in referencesToRemove {
topicGraph.edges[reference]?.removeAll(where: { $0.id == bundle.id })
topicGraph.reverseEdges[reference]?.removeAll(where: { $0.id == bundle.id })
topicGraph.edges[reference]?.removeAll(where: { $0.bundleID == bundle.id })
topicGraph.reverseEdges[reference]?.removeAll(where: { $0.bundleID == bundle.id })
topicGraph.nodes[reference] = nil
}
}
Expand Down Expand Up @@ -2738,7 +2738,7 @@ public class DocumentationContext {
}

private func externalEntity(with reference: ResolvedTopicReference) -> LinkResolver.ExternalEntity? {
return configuration.externalDocumentationConfiguration.sources[reference.id].map({ $0.entity(with: reference) })
return configuration.externalDocumentationConfiguration.sources[reference.bundleID].map({ $0.entity(with: reference) })
?? configuration.convertServiceConfiguration.fallbackResolver?.entityIfPreviouslyResolved(with: reference)
}

Expand Down Expand Up @@ -2904,7 +2904,7 @@ public class DocumentationContext {
/// - asset: The new asset for this name.
/// - parent: The topic where the asset is referenced.
public func updateAsset(named name: String, asset: DataAsset, in parent: ResolvedTopicReference) {
assetManagers[parent.id]?.update(name: name, asset: asset)
assetManagers[parent.bundleID]?.update(name: name, asset: asset)
}

/// Attempt to resolve an asset given its name and the topic it's referenced in.
Expand All @@ -2915,7 +2915,7 @@ public class DocumentationContext {
/// - type: A restriction for what type of asset to resolve.
/// - Returns: The data that's associated with an image asset if it was found, otherwise `nil`.
public func resolveAsset(named name: String, in parent: ResolvedTopicReference, withType type: AssetType? = nil) -> DataAsset? {
resolveAsset(named: name, bundleID: parent.id, withType: type)
resolveAsset(named: name, bundleID: parent.bundleID, withType: type)
}

func resolveAsset(named name: String, bundleID: DocumentationBundle.Identifier, withType expectedType: AssetType?) -> DataAsset? {
Expand Down Expand Up @@ -2959,7 +2959,7 @@ public class DocumentationContext {
///
/// - Returns: The best matching storage key if it was found, otherwise `nil`.
public func identifier(forAssetName name: String, in parent: ResolvedTopicReference) -> String? {
if let assetManager = assetManagers[parent.id] {
if let assetManager = assetManagers[parent.bundleID] {
if let localName = assetManager.bestKey(forAssetName: name) {
return localName
} else if let fallbackAssetManager = configuration.convertServiceConfiguration.fallbackResolver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct DocumentationCurator {
let sourceArticlePath = NodeURLGenerator.Path.article(bundleName: bundle.displayName, articleName: articleFilename).stringValue

let reference = ResolvedTopicReference(
id: resolved.id,
bundleID: resolved.bundleID,
path: sourceArticlePath,
sourceLanguages: resolved.sourceLanguages)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE

@available(*, deprecated, renamed: "id", message: "Use 'id' instead. This deprecated API will be removed after 6.2 is released")
public var bundleIdentifier: String {
id.rawValue
bundleID.rawValue
}

/// The bundle identifier for the reference resolver in the other process.
public let id: DocumentationBundle.Identifier
public let bundleID: DocumentationBundle.Identifier

/// Creates a new reference resolver that interacts with another executable.
///
Expand All @@ -82,13 +82,13 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
throw Error.invalidBundleIdentifierOutputFromExecutable(processLocation)
}

self.id = .init(rawValue: decodedBundleIdentifier)
self.bundleID = .init(rawValue: decodedBundleIdentifier)
self.externalLinkResolvingClient = longRunningProcess
}

@available(*, deprecated, renamed: "init(id:server:convertRequestIdentifier:)", message: "Use 'init(id:server:convertRequestIdentifier:)' instead. This deprecated API will be removed after 6.2 is released")
@available(*, deprecated, renamed: "init(bundleID:server:convertRequestIdentifier:)", message: "Use 'init(bundleID:server:convertRequestIdentifier:)' instead. This deprecated API will be removed after 6.2 is released")
public init(bundleIdentifier: String, server: DocumentationServer, convertRequestIdentifier: String?) throws {
self.id = .init(rawValue: bundleIdentifier)
self.bundleID = .init(rawValue: bundleIdentifier)
self.externalLinkResolvingClient = LongRunningService(
server: server, convertRequestIdentifier: convertRequestIdentifier)
}
Expand All @@ -102,7 +102,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
/// - server: The server to send link resolution requests to.
/// - convertRequestIdentifier: The identifier that the resolver will use for convert requests that it sends to the server.
public init(id: DocumentationBundle.Identifier, server: DocumentationServer, convertRequestIdentifier: String?) throws {
self.id = id
self.bundleID = id
self.externalLinkResolvingClient = LongRunningService(
server: server, convertRequestIdentifier: convertRequestIdentifier)
}
Expand All @@ -115,7 +115,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
return resolved

case let .unresolved(unresolvedReference):
guard unresolvedReference.id == id else {
guard unresolvedReference.bundleID == bundleID else {
fatalError("""
Attempted to resolve a local reference externally: \(unresolvedReference.description.singleQuoted).
DocC should never pass a reference to an external resolver unless it matches that resolver's bundle identifier.
Expand Down Expand Up @@ -147,7 +147,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
guard let resolvedInformation = try? resolveInformationForSymbolIdentifier(preciseIdentifier) else { return nil }

let reference = ResolvedTopicReference(
id: "com.externally.resolved.symbol",
bundleID: "com.externally.resolved.symbol",
path: "/\(preciseIdentifier)",
sourceLanguages: sourceLanguages(for: resolvedInformation)
)
Expand Down Expand Up @@ -255,7 +255,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE

private func resolvedReference(for resolvedInformation: ResolvedInformation) -> ResolvedTopicReference {
return ResolvedTopicReference(
id: id,
bundleID: bundleID,
path: resolvedInformation.url.path,
fragment: resolvedInformation.url.fragment,
sourceLanguages: sourceLanguages(for: resolvedInformation)
Expand Down Expand Up @@ -779,13 +779,13 @@ extension OutOfProcessReferenceResolver: ConvertServiceFallbackResolver {
}

func resolveInformationForAsset(named assetName: String) throws -> DataAsset {
let assetReference = AssetReference(assetName: assetName, bundleID: id)
let assetReference = AssetReference(assetName: assetName, bundleID: bundleID)
if let asset = assetCache[assetReference] {
return asset
}

let response = try externalLinkResolvingClient.sendAndWait(
request: Request.asset(AssetReference(assetName: assetName, bundleID: id))
request: Request.asset(AssetReference(assetName: assetName, bundleID: bundleID))
) as Response

switch response {
Expand All @@ -798,8 +798,4 @@ extension OutOfProcessReferenceResolver: ConvertServiceFallbackResolver {
throw Error.unexpectedResponse(response: response, requestDescription: "asset")
}
}

var bundleID: DocumentationBundle.Identifier {
id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class ExternalPathHierarchyResolver {
else {
return nil
}
return ResolvedTopicReference(id: .init(rawValue: bundleID), path: url.path, fragment: url.fragment, sourceLanguage: .swift)
return ResolvedTopicReference(bundleID: .init(rawValue: bundleID), path: url.path, fragment: url.fragment, sourceLanguage: .swift)
}
let dependencies = RenderReferenceDependencies(
topicReferences: topicReferences,
Expand Down Expand Up @@ -126,7 +126,7 @@ final class ExternalPathHierarchyResolver {
symbols.reserveCapacity(linkDestinationSummaries.count)
for entity in linkDestinationSummaries {
let reference = ResolvedTopicReference(
id: .init(rawValue: entity.referenceURL.host!),
bundleID: .init(rawValue: entity.referenceURL.host!),
path: entity.referenceURL.path,
fragment: entity.referenceURL.fragment,
sourceLanguage: entity.language
Expand All @@ -150,7 +150,7 @@ final class ExternalPathHierarchyResolver {
continue
}
let identifier = identifiers[index]
self.resolvedReferences[identifier] = ResolvedTopicReference(id: fileRepresentation.bundleID, path: url.path, fragment: url.fragment, sourceLanguage: .swift)
self.resolvedReferences[identifier] = ResolvedTopicReference(bundleID: fileRepresentation.bundleID, path: url.path, fragment: url.fragment, sourceLanguage: .swift)
}
}
// Finally, the Identifier -> Symbol mapping can be constructed by iterating over the nodes and looking up the reference for each USR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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.id,
if let bundleID = unresolvedReference.bundleID,
!context._registeredBundles.contains(where: { $0.id == bundleID || urlReadablePath($0.displayName) == bundleID.rawValue })
{
return .failure(unresolvedReference, TopicReferenceResolutionErrorInfo("No external resolver registered for '\(bundleID)'."))
Expand Down Expand Up @@ -169,7 +169,7 @@ private final class FallbackResolverBasedLinkResolver {

private func resolve(_ unresolvedReference: UnresolvedTopicReference, in parent: ResolvedTopicReference, fromSymbolLink isCurrentlyResolvingSymbolLink: Bool, context: DocumentationContext) -> TopicReferenceResolutionResult? {
// Check if a fallback reference resolver should resolve this
let referenceID = unresolvedReference.id ?? parent.id
let referenceID = unresolvedReference.bundleID ?? parent.bundleID
guard let fallbackResolver = context.configuration.convertServiceConfiguration.fallbackResolver,
// This uses an underscored internal variant of `registeredBundles` to avoid deprecation warnings and remain compatible with legacy data providers.
let knownBundleID = context._registeredBundles.first(where: { $0.id == referenceID || urlReadablePath($0.displayName) == referenceID.rawValue })?.id,
Expand All @@ -184,7 +184,7 @@ private final class FallbackResolverBasedLinkResolver {
var allCandidateURLs = [URL]()

let alreadyResolved = ResolvedTopicReference(
id: referenceID,
bundleID: referenceID,
path: unresolvedReference.path.prependingLeadingSlash,
fragment: unresolvedReference.topicURL.components.fragment,
sourceLanguages: parent.sourceLanguages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class PathHierarchyBasedLinkResolver {
func unregisterBundle(identifier: DocumentationBundle.Identifier) {
var newMap = BidirectionalMap<ResolvedIdentifier, ResolvedTopicReference>()
for (id, reference) in resolvedReferenceMap {
if reference.id == identifier {
if reference.bundleID == identifier {
pathHierarchy.removeNodeWithID(id)
} else {
newMap[id] = reference
Expand Down Expand Up @@ -301,7 +301,7 @@ final class PathHierarchyBasedLinkResolver {
}

return ResolvedTopicReference(
id: bundle.documentationRootReference.id,
bundleID: bundle.documentationRootReference.bundleID,
path: NodeURLGenerator.Path.documentationFolder + path,
sourceLanguages: symbol.sourceLanguages
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ enum GeneratedDocumentationTopics {

// Create the collection topic reference
let collectionReference = ResolvedTopicReference(
id: bundle.id,
bundleID: bundle.id,
path: NodeURLGenerator.Path.documentationCuration(
parentPath: parent.path,
articleName: title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension ResolvedTopicReference {
let path = symbolReference.path.isEmpty ? "" : "/" + symbolReference.path

self.init(
id: bundle.documentationRootReference.id,
bundleID: bundle.documentationRootReference.bundleID,
path: bundle.documentationRootReference.appendingPath(moduleName + path).path,
fragment: nil,
sourceLanguages: symbolReference.interfaceLanguages
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, bundle.id == reference.id else {
guard let bundle = context.bundle, bundle.id == reference.bundleID else {
// Don't return anything for external references that don't have a bundle in the context.
return []
}
Expand Down
Loading

0 comments on commit f86a125

Please sign in to comment.