Skip to content

Commit aebc226

Browse files
authored
Extract link resolution code from the documentation context (#306)
* Extract most link resolution code from DocumentationContext * Stop waiting for request if external resolver client encounters fails * Remove unnecessary calls to remove temp files in tests. Also, fix a handful of typos in tests and comments. * Add missing symbol relationships in test data * Avoid changing kind of symbol in tests via known disambiguation * Fix various correctness issues in test symbol graph files * Fix inconsistent path component in test symbol graph files * Minor grammar: 'indeterministic' -> 'non-deterministic'
1 parent 9f5c31d commit aebc226

File tree

48 files changed

+845
-814
lines changed

Some content is hidden

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

48 files changed

+845
-814
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 29 additions & 509 deletions
Large diffs are not rendered by default.

Sources/SwiftDocC/Infrastructure/DocumentationCurator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct DocumentationCurator {
3838
}
3939

4040
// Optimization for absolute links.
41-
if let cached = context.referenceFor(absoluteSymbolPath: destination, parent: resolved) {
41+
if let cached = context.documentationCacheBasedLinkResolver.referenceFor(absoluteSymbolPath: destination, parent: resolved) {
4242
return cached
4343
}
4444

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ExternalReferenceResolverServiceClient {
6868
}
6969
} catch {
7070
result = .failure(.failedToEncodeRequest(underlyingError: error))
71+
resultGroup.leave()
7172
}
7273
}
7374

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

Lines changed: 540 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ enum GeneratedDocumentationTopics {
209209
/// - symbolsURLHierarchy: A symbol graph hierarchy as created during symbol registration.
210210
/// - context: A documentation context to update.
211211
/// - bundle: The current documentation bundle.
212-
static func createInheritedSymbolsAPICollections(relationships: Set<SymbolGraph.Relationship>, symbolsURLHierarchy: inout BidirectionalTree<ResolvedTopicReference>, context: DocumentationContext, bundle: DocumentationBundle) throws {
212+
static func createInheritedSymbolsAPICollections(relationships: Set<SymbolGraph.Relationship>, parentOfFunction: (ResolvedTopicReference) -> ResolvedTopicReference?, context: DocumentationContext, bundle: DocumentationBundle) throws {
213213
var inheritanceIndex = InheritedSymbols()
214214

215215
// Walk the symbol graph relationships and look for parent <-> child links that stem in a different module.
@@ -227,14 +227,14 @@ enum GeneratedDocumentationTopics {
227227
let extends = child.symbol?.mixins[SymbolGraph.Symbol.Swift.Extension.mixinKey] as? SymbolGraph.Symbol.Swift.Extension {
228228
var originParentSymbol: ResolvedTopicReference? = nil
229229
if let originSymbol = context.symbolIndex[origin.identifier] {
230-
originParentSymbol = try? symbolsURLHierarchy.parent(of: originSymbol.reference)
230+
originParentSymbol = parentOfFunction(originSymbol.reference)
231231
}
232232
// Add the inherited symbol to the index.
233233
try inheritanceIndex.add(child.reference, to: parent.reference, originDisplayName: origin.displayName, originParentSymbol: originParentSymbol, extendedModuleName: extends.extendedModule)
234234
}
235235
}
236236

237-
// Create the API Collection nodes and the neccessary topic graph curation.
237+
// Create the API Collection nodes and the necessary topic graph curation.
238238
for (typeReference, collections) in inheritanceIndex.implementingTypes where !collections.inheritedFromTypeName.isEmpty {
239239
for (_, collection) in collections.inheritedFromTypeName where !collection.identifiers.isEmpty {
240240
// Create a collection for the given provider type's inherited symbols

Sources/SwiftDocC/Model/Rendering/RenderContentCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ struct RenderContentCompiler: MarkupVisitor {
134134
}
135135

136136
func resolveSymbolReference(destination: String) -> ResolvedTopicReference? {
137-
if let cached = context.referenceFor(absoluteSymbolPath: destination, parent: identifier) {
137+
if let cached = context.documentationCacheBasedLinkResolver.referenceFor(absoluteSymbolPath: destination, parent: identifier) {
138138
return cached
139139
}
140140

Sources/SwiftDocC/Semantics/MarkupReferenceResolver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct MarkupReferenceResolver: MarkupRewriter {
113113
}
114114

115115
mutating func resolveAbsoluteSymbolLink(unresolvedDestination: String, elementRange range: SourceRange?) -> String {
116-
if let cached = context.referenceFor(absoluteSymbolPath: unresolvedDestination, parent: rootReference) {
116+
if let cached = context.documentationCacheBasedLinkResolver.referenceFor(absoluteSymbolPath: unresolvedDestination, parent: rootReference) {
117117
guard context.topicGraph.isLinkable(cached) == true else {
118118
problems.append(disabledLinkDestinationProblem(reference: cached, source: source, range: range, severity: .warning))
119119
return unresolvedDestination

0 commit comments

Comments
 (0)