Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 09b9720

Browse files
committed
Use typealias resolution when creating relationships
1 parent 0df8f0a commit 09b9720

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Sources/SwiftDoc/Interface.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ public final class Interface {
1010
self.imports = imports
1111
self.symbols = symbols
1212

13-
self.symbolsGroupedByIdentifier = Dictionary(grouping: symbols, by: { $0.id })
14-
self.symbolsGroupedByQualifiedName = Dictionary(grouping: symbols, by: { $0.id.description })
15-
self.topLevelSymbols = symbols.filter { $0.api is Type || $0.id.pathComponents.isEmpty }
13+
let symbolsGroupedByIdentifier = Dictionary(grouping: symbols, by: { $0.id })
14+
let symbolsGroupedByQualifiedName = Dictionary(grouping: symbols, by: { $0.id.description })
15+
16+
self.symbolsGroupedByIdentifier = symbolsGroupedByIdentifier
17+
self.symbolsGroupedByQualifiedName = symbolsGroupedByQualifiedName
18+
self.topLevelSymbols = symbols.filter { $0.api is Type || $0.id.context.isEmpty }
1619

1720
self.relationships = {
1821
let extensionsByExtendedType: [String: [Extension]] = Dictionary(grouping: symbols.flatMap { $0.context.compactMap { $0 as? Extension } }, by: { $0.extendedType })
1922

2023
var relationships: Set<Relationship> = []
2124
for symbol in symbols {
22-
2325
let lastDeclarationScope = symbol.context.last(where: { $0 is Extension || $0 is Symbol })
2426

2527
if let container = lastDeclarationScope as? Symbol {
@@ -40,8 +42,7 @@ public final class Interface {
4042
}
4143

4244
if let `extension` = lastDeclarationScope as? Extension {
43-
if let extended = symbols.first(where: { $0.api is Type && $0.id.matches(`extension`.extendedType) }) {
44-
45+
for extended in symbolsGroupedByIdentifier.named(`extension`.extendedType, resolvingTypealiases: true) {
4546
let predicate: Relationship.Predicate
4647
switch extended.api {
4748
case is Protocol:
@@ -66,7 +67,7 @@ public final class Interface {
6667
inheritedTypeNames = Set(inheritedTypeNames.flatMap { $0.split(separator: "&").map { $0.trimmingCharacters(in: .whitespaces) } })
6768

6869
for name in inheritedTypeNames {
69-
let inheritedTypes = symbols.filter({ ($0.api is Class || $0.api is Protocol) && $0.id.description == name })
70+
let inheritedTypes = symbolsGroupedByIdentifier.named(name, resolvingTypealiases: true).filter({ ($0.api is Class || $0.api is Protocol) && $0.id.description == name })
7071
if inheritedTypes.isEmpty {
7172
let inherited = Symbol(api: Unknown(name: name), context: [], declaration: [], documentation: nil, sourceRange: nil)
7273
relationships.insert(Relationship(subject: symbol, predicate: .conformsTo, object: inherited))
@@ -115,7 +116,6 @@ public final class Interface {
115116
}
116117

117118
return classClusters
118-
119119
}
120120

121121
public let relationships: [Relationship]

0 commit comments

Comments
 (0)