Skip to content

Commit f86a125

Browse files
committed
Prefer bundleID over id for types that scoped inside bundle
1 parent e3faaf2 commit f86a125

File tree

94 files changed

+578
-582
lines changed

Some content is hidden

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

94 files changed

+578
-582
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, bundle.id == topicReference.id else { return nil }
270+
guard let bundle = context.bundle, bundle.id == topicReference.bundleID else { return nil }
271271
let renderer = DocumentationContentRenderer(documentationContext: context, bundle: bundle)
272272

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

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ extension ResolvedTopicReference {
438438
let normalizedPath = NodeURLGenerator.fileSafeReferencePath(self, lowercased: true)
439439

440440
return NavigatorIndex.Identifier(
441-
bundleIdentifier: id.rawValue.lowercased(),
441+
bundleIdentifier: bundleID.rawValue.lowercased(),
442442
path: "/" + normalizedPath,
443443
fragment: fragment,
444444
languageIdentifier: languageIdentifier

Sources/SwiftDocC/Infrastructure/DocumentationBundle.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public struct DocumentationBundle {
127127
self.customHeader = customHeader
128128
self.customFooter = customFooter
129129
self.themeSettings = themeSettings
130-
self.rootReference = ResolvedTopicReference(id: info.id, path: "/", sourceLanguage: .swift)
131-
self.documentationRootReference = ResolvedTopicReference(id: info.id, path: NodeURLGenerator.Path.documentationFolder, sourceLanguage: .swift)
132-
self.tutorialTableOfContentsContainer = ResolvedTopicReference(id: info.id, path: NodeURLGenerator.Path.tutorialsFolder, sourceLanguage: .swift)
130+
self.rootReference = ResolvedTopicReference(bundleID: info.id, path: "/", sourceLanguage: .swift)
131+
self.documentationRootReference = ResolvedTopicReference(bundleID: info.id, path: NodeURLGenerator.Path.documentationFolder, sourceLanguage: .swift)
132+
self.tutorialTableOfContentsContainer = ResolvedTopicReference(bundleID: info.id, path: NodeURLGenerator.Path.tutorialsFolder, sourceLanguage: .swift)
133133
self.tutorialsContainerReference = tutorialTableOfContentsContainer.appendingPath(urlReadablePath(info.displayName))
134134
self.articlesDocumentationRootReference = documentationRootReference.appendingPath(urlReadablePath(info.displayName))
135135
}

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ public class DocumentationContext {
915915
let (url, analyzed) = analyzedDocument
916916

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

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

13371337
let symbolPath = NodeURLGenerator.Path.documentation(path: url.components.path).stringValue
13381338
let symbolReference = ResolvedTopicReference(
1339-
id: reference.id,
1339+
bundleID: reference.bundleID,
13401340
path: symbolPath,
13411341
fragment: nil,
13421342
sourceLanguages: reference.sourceLanguages
@@ -1948,7 +1948,7 @@ public class DocumentationContext {
19481948
let title = articleResult.source.deletingPathExtension().lastPathComponent
19491949
// Create a new root-looking reference
19501950
let reference = ResolvedTopicReference(
1951-
id: bundle.id,
1951+
bundleID: bundle.id,
19521952
path: NodeURLGenerator.Path.documentation(path: title).stringValue,
19531953
sourceLanguages: [DocumentationContext.defaultLanguage(in: nil /* article-only content has no source language information */)]
19541954
)
@@ -1987,7 +1987,7 @@ public class DocumentationContext {
19871987
let path = NodeURLGenerator.Path.documentation(path: title).stringValue
19881988
let sourceLanguage = DocumentationContext.defaultLanguage(in: [])
19891989

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

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

20542054
let reference = ResolvedTopicReference(
2055-
id: bundle.id,
2055+
bundleID: bundle.id,
20562056
path: path,
20572057
sourceLanguages: availableSourceLanguages
20582058
// FIXME: Pages in article-only catalogs should not be inferred as "Swift" as a fallback
@@ -2687,12 +2687,12 @@ public class DocumentationContext {
26872687
*/
26882688
private func unregister(_ bundle: DocumentationBundle) {
26892689
let referencesToRemove = topicGraph.nodes.keys.filter {
2690-
$0.id == bundle.id
2690+
$0.bundleID == bundle.id
26912691
}
26922692

26932693
for reference in referencesToRemove {
2694-
topicGraph.edges[reference]?.removeAll(where: { $0.id == bundle.id })
2695-
topicGraph.reverseEdges[reference]?.removeAll(where: { $0.id == bundle.id })
2694+
topicGraph.edges[reference]?.removeAll(where: { $0.bundleID == bundle.id })
2695+
topicGraph.reverseEdges[reference]?.removeAll(where: { $0.bundleID == bundle.id })
26962696
topicGraph.nodes[reference] = nil
26972697
}
26982698
}
@@ -2738,7 +2738,7 @@ public class DocumentationContext {
27382738
}
27392739

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

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

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

29212921
func resolveAsset(named name: String, bundleID: DocumentationBundle.Identifier, withType expectedType: AssetType?) -> DataAsset? {
@@ -2959,7 +2959,7 @@ public class DocumentationContext {
29592959
///
29602960
/// - Returns: The best matching storage key if it was found, otherwise `nil`.
29612961
public func identifier(forAssetName name: String, in parent: ResolvedTopicReference) -> String? {
2962-
if let assetManager = assetManagers[parent.id] {
2962+
if let assetManager = assetManagers[parent.bundleID] {
29632963
if let localName = assetManager.bestKey(forAssetName: name) {
29642964
return localName
29652965
} else if let fallbackAssetManager = configuration.convertServiceConfiguration.fallbackResolver {

Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct DocumentationCurator {
9494
let sourceArticlePath = NodeURLGenerator.Path.article(bundleName: bundle.displayName, articleName: articleFilename).stringValue
9595

9696
let reference = ResolvedTopicReference(
97-
id: resolved.id,
97+
bundleID: resolved.bundleID,
9898
path: sourceArticlePath,
9999
sourceLanguages: resolved.sourceLanguages)
100100

Sources/SwiftDocC/Infrastructure/External Data/OutOfProcessReferenceResolver.swift

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
5353

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

5959
/// The bundle identifier for the reference resolver in the other process.
60-
public let id: DocumentationBundle.Identifier
60+
public let bundleID: DocumentationBundle.Identifier
6161

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

85-
self.id = .init(rawValue: decodedBundleIdentifier)
85+
self.bundleID = .init(rawValue: decodedBundleIdentifier)
8686
self.externalLinkResolvingClient = longRunningProcess
8787
}
8888

89-
@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")
89+
@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")
9090
public init(bundleIdentifier: String, server: DocumentationServer, convertRequestIdentifier: String?) throws {
91-
self.id = .init(rawValue: bundleIdentifier)
91+
self.bundleID = .init(rawValue: bundleIdentifier)
9292
self.externalLinkResolvingClient = LongRunningService(
9393
server: server, convertRequestIdentifier: convertRequestIdentifier)
9494
}
@@ -102,7 +102,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
102102
/// - server: The server to send link resolution requests to.
103103
/// - convertRequestIdentifier: The identifier that the resolver will use for convert requests that it sends to the server.
104104
public init(id: DocumentationBundle.Identifier, server: DocumentationServer, convertRequestIdentifier: String?) throws {
105-
self.id = id
105+
self.bundleID = id
106106
self.externalLinkResolvingClient = LongRunningService(
107107
server: server, convertRequestIdentifier: convertRequestIdentifier)
108108
}
@@ -115,7 +115,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
115115
return resolved
116116

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

149149
let reference = ResolvedTopicReference(
150-
id: "com.externally.resolved.symbol",
150+
bundleID: "com.externally.resolved.symbol",
151151
path: "/\(preciseIdentifier)",
152152
sourceLanguages: sourceLanguages(for: resolvedInformation)
153153
)
@@ -255,7 +255,7 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
255255

256256
private func resolvedReference(for resolvedInformation: ResolvedInformation) -> ResolvedTopicReference {
257257
return ResolvedTopicReference(
258-
id: id,
258+
bundleID: bundleID,
259259
path: resolvedInformation.url.path,
260260
fragment: resolvedInformation.url.fragment,
261261
sourceLanguages: sourceLanguages(for: resolvedInformation)
@@ -779,13 +779,13 @@ extension OutOfProcessReferenceResolver: ConvertServiceFallbackResolver {
779779
}
780780

781781
func resolveInformationForAsset(named assetName: String) throws -> DataAsset {
782-
let assetReference = AssetReference(assetName: assetName, bundleID: id)
782+
let assetReference = AssetReference(assetName: assetName, bundleID: bundleID)
783783
if let asset = assetCache[assetReference] {
784784
return asset
785785
}
786786

787787
let response = try externalLinkResolvingClient.sendAndWait(
788-
request: Request.asset(AssetReference(assetName: assetName, bundleID: id))
788+
request: Request.asset(AssetReference(assetName: assetName, bundleID: bundleID))
789789
) as Response
790790

791791
switch response {
@@ -798,8 +798,4 @@ extension OutOfProcessReferenceResolver: ConvertServiceFallbackResolver {
798798
throw Error.unexpectedResponse(response: response, requestDescription: "asset")
799799
}
800800
}
801-
802-
var bundleID: DocumentationBundle.Identifier {
803-
id
804-
}
805801
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ final class ExternalPathHierarchyResolver {
9898
else {
9999
return nil
100100
}
101-
return ResolvedTopicReference(id: .init(rawValue: bundleID), path: url.path, fragment: url.fragment, sourceLanguage: .swift)
101+
return ResolvedTopicReference(bundleID: .init(rawValue: bundleID), path: url.path, fragment: url.fragment, sourceLanguage: .swift)
102102
}
103103
let dependencies = RenderReferenceDependencies(
104104
topicReferences: topicReferences,
@@ -126,7 +126,7 @@ final class ExternalPathHierarchyResolver {
126126
symbols.reserveCapacity(linkDestinationSummaries.count)
127127
for entity in linkDestinationSummaries {
128128
let reference = ResolvedTopicReference(
129-
id: .init(rawValue: entity.referenceURL.host!),
129+
bundleID: .init(rawValue: entity.referenceURL.host!),
130130
path: entity.referenceURL.path,
131131
fragment: entity.referenceURL.fragment,
132132
sourceLanguage: entity.language
@@ -150,7 +150,7 @@ final class ExternalPathHierarchyResolver {
150150
continue
151151
}
152152
let identifier = identifiers[index]
153-
self.resolvedReferences[identifier] = ResolvedTopicReference(id: fileRepresentation.bundleID, path: url.path, fragment: url.fragment, sourceLanguage: .swift)
153+
self.resolvedReferences[identifier] = ResolvedTopicReference(bundleID: fileRepresentation.bundleID, path: url.path, fragment: url.fragment, sourceLanguage: .swift)
154154
}
155155
}
156156
// Finally, the Identifier -> Symbol mapping can be constructed by iterating over the nodes and looking up the reference for each USR.

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

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

9494
// Check if this is a link to an external documentation source that should have previously been resolved in `DocumentationContext.preResolveExternalLinks(...)`
95-
if let bundleID = unresolvedReference.id,
95+
if let bundleID = unresolvedReference.bundleID,
9696
!context._registeredBundles.contains(where: { $0.id == bundleID || urlReadablePath($0.displayName) == bundleID.rawValue })
9797
{
9898
return .failure(unresolvedReference, TopicReferenceResolutionErrorInfo("No external resolver registered for '\(bundleID)'."))
@@ -169,7 +169,7 @@ private final class FallbackResolverBasedLinkResolver {
169169

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

186186
let alreadyResolved = ResolvedTopicReference(
187-
id: referenceID,
187+
bundleID: referenceID,
188188
path: unresolvedReference.path.prependingLeadingSlash,
189189
fragment: unresolvedReference.topicURL.components.fragment,
190190
sourceLanguages: parent.sourceLanguages

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class PathHierarchyBasedLinkResolver {
2828
func unregisterBundle(identifier: DocumentationBundle.Identifier) {
2929
var newMap = BidirectionalMap<ResolvedIdentifier, ResolvedTopicReference>()
3030
for (id, reference) in resolvedReferenceMap {
31-
if reference.id == identifier {
31+
if reference.bundleID == identifier {
3232
pathHierarchy.removeNodeWithID(id)
3333
} else {
3434
newMap[id] = reference
@@ -301,7 +301,7 @@ final class PathHierarchyBasedLinkResolver {
301301
}
302302

303303
return ResolvedTopicReference(
304-
id: bundle.documentationRootReference.id,
304+
bundleID: bundle.documentationRootReference.bundleID,
305305
path: NodeURLGenerator.Path.documentationFolder + path,
306306
sourceLanguages: symbol.sourceLanguages
307307
)

Sources/SwiftDocC/Infrastructure/Symbol Graph/GeneratedDocumentationTopics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ enum GeneratedDocumentationTopics {
107107

108108
// Create the collection topic reference
109109
let collectionReference = ResolvedTopicReference(
110-
id: bundle.id,
110+
bundleID: bundle.id,
111111
path: NodeURLGenerator.Path.documentationCuration(
112112
parentPath: parent.path,
113113
articleName: title

Sources/SwiftDocC/Infrastructure/Symbol Graph/ResolvedTopicReference+Symbol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension ResolvedTopicReference {
2020
let path = symbolReference.path.isEmpty ? "" : "/" + symbolReference.path
2121

2222
self.init(
23-
id: bundle.documentationRootReference.id,
23+
bundleID: bundle.documentationRootReference.bundleID,
2424
path: bundle.documentationRootReference.appendingPath(moduleName + path).path,
2525
fragment: nil,
2626
sourceLanguages: symbolReference.interfaceLanguages

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, bundle.id == reference.id else {
314+
guard let bundle = context.bundle, bundle.id == reference.bundleID else {
315315
// Don't return anything for external references that don't have a bundle in the context.
316316
return []
317317
}

0 commit comments

Comments
 (0)