Skip to content

Commit 06f70dc

Browse files
committed
remove changes relevant to path contractions + adapt tests
1 parent 97153b8 commit 06f70dc

File tree

8 files changed

+209
-380
lines changed

8 files changed

+209
-380
lines changed

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

+4-54
Original file line numberDiff line numberDiff line change
@@ -335,65 +335,15 @@ final class DocumentationCacheBasedLinkResolver {
335335
let moduleName: String
336336
var languages: Set<SourceLanguage>
337337
}
338-
var pathCollisionInfo = [[String]: [PathCollisionInfo]]()
338+
var pathCollisionInfo = [String: [PathCollisionInfo]]()
339339
pathCollisionInfo.reserveCapacity(totalSymbolCount)
340340

341341
// Group symbols by path from all of the available symbol graphs
342342
for (moduleName, symbolGraph) in unifiedGraphs {
343343
let symbols = Array(symbolGraph.symbols.values)
344-
345-
let referenceMap = symbols.concurrentMap { symbol in
346-
(symbol, referencesWithoutDisambiguationFor(symbol, moduleName: moduleName, bundle: bundle, context: context))
347-
}.reduce(into: [String: [SourceLanguage: ResolvedTopicReference]](), { result, next in
348-
let (symbol, references) = next
349-
for reference in references {
350-
result[symbol.uniqueIdentifier, default: [:]][reference.sourceLanguage] = reference
351-
}
352-
})
353-
354-
let parentMap = symbolGraph.relationshipsByLanguage.reduce(into: [String: [SourceLanguage: String]](), { parentMap, next in
355-
let (selector, relationships) = next
356-
guard let language = SourceLanguage(knownLanguageIdentifier: selector.interfaceLanguage) else {
357-
return
358-
}
359-
360-
for relationship in relationships {
361-
switch relationship.kind {
362-
case .memberOf, .requirementOf, .declaredIn:
363-
parentMap[relationship.source, default: [:]][language] = relationship.target
364-
default:
365-
break
366-
}
367-
}
368-
})
369-
370-
let pathsAndLanguages: [[([String], SourceLanguage)]] = symbols.concurrentMap { symbol in
371-
guard let references = referenceMap[symbol.uniqueIdentifier] else {
372-
return []
373-
}
374-
375-
return references.map { language, reference in
376-
var prefixLength: Int
377-
if let parentId = parentMap[symbol.uniqueIdentifier]?[language],
378-
let parentReference = referenceMap[parentId]?[language] ?? referenceMap[parentId]?.values.first {
379-
// This is a child of some other symbol
380-
prefixLength = parentReference.pathComponents.count
381-
} else {
382-
// This is a top-level symbol or another symbol without parent (e.g. default implementation)
383-
prefixLength = reference.pathComponents.count-1
384-
}
385-
386-
// PathComponents can have prefixes which are not known locally. In that case,
387-
// the "empty" segments will be cut out later on. We follow the same logic here, as otherwise
388-
// some collisions would not be detected.
389-
// E.g. consider an extension to an external nested type `SomeModule.SomeStruct.SomeStruct`. The
390-
// parent of this extended type symbol is `SomeModule`, however, the path for the extended type symbol
391-
// is `SomeModule/SomeStruct/SomeStruct`, later on, this will change to `SomeModule/SomeStruct`. Now, if
392-
// we also extend `SomeModule.SomeStruct`, the paths for both extensions could collide. To recognize (and resolve)
393-
// the collision here, we work with the same, shortened paths.
394-
return ((reference.pathComponents[0..<prefixLength] + [reference.pathComponents.last!]).map{ $0.lowercased() }, reference.sourceLanguage)
395-
}
396-
}
344+
let pathsAndLanguages: [[(String, SourceLanguage)]] = symbols.concurrentMap { referencesWithoutDisambiguationFor($0, moduleName: moduleName, bundle: bundle, context: context).map {
345+
($0.path.lowercased(), $0.sourceLanguage)
346+
} }
397347

398348
for (symbol, symbolPathsAndLanguages) in zip(symbols, pathsAndLanguages) {
399349
for (path, language) in symbolPathsAndLanguages {

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

-11
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,6 @@ struct PathHierarchy {
165165
parent = child
166166
components = components.dropFirst()
167167
}
168-
169-
// Symbols corresponding to nested types may appear outside of their original context, where
170-
// their parent type may not be present. This happens e.g. for extensions to external nested
171-
// types. In such cases, the nested type should be a direct child of whatever its parent is
172-
// in this different context. Any other behavior would lead to truly empty pages.
173-
var titlePrefix = node.symbol!.title.split(separator: ".").dropLast()
174-
while !components.isEmpty && !titlePrefix.isEmpty && components.last! == titlePrefix.last! {
175-
titlePrefix = titlePrefix.dropLast()
176-
components = components.dropLast()
177-
}
178-
179168
for component in components {
180169
let component = Self.parse(pathComponent: component[...])
181170
let nodeWithoutSymbol = Node(name: component.name)

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

+5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ import SymbolKit
1313
// MARK: Custom Relationship Kind Identifiers
1414

1515
extension SymbolGraph.Relationship.Kind {
16+
/// This relationship connects top-level extended type symbols the
17+
/// respective extended module symbol.
1618
static let declaredIn = Self(rawValue: "declaredIn")
1719

20+
/// This relationship markes a parent-child hierarchy between a nested
21+
/// extended type symbol and its parent extended type symbol. It mirrors the
22+
/// `memberOf` relationship between the two respective original type symbols.
1823
static let inContextOf = Self(rawValue: "inContextOf")
1924
}
2025

0 commit comments

Comments
 (0)