|
1 | 1 | /* |
2 | 2 | This source file is part of the Swift.org open source project |
3 | 3 |
|
4 | | - Copyright (c) 2021 Apple Inc. and the Swift project authors |
| 4 | + Copyright (c) 2021-2022 Apple Inc. and the Swift project authors |
5 | 5 | Licensed under Apache License v2.0 with Runtime Library Exception |
6 | 6 |
|
7 | 7 | See https://swift.org/LICENSE.txt for license information |
@@ -40,25 +40,35 @@ enum GeneratedDocumentationTopics { |
40 | 40 | /// - reference: The parent type reference. |
41 | 41 | /// - originDisplayName: The origin display name as provided by the symbol graph. |
42 | 42 | /// - extendedModuleName: Extended module name. |
43 | | - mutating func add(_ childReference: ResolvedTopicReference, to reference: ResolvedTopicReference, originDisplayName: String, extendedModuleName: String) throws { |
44 | | - // Detect the path components of the providing the default implementation. |
45 | | - let typeComponents = originDisplayName.components(separatedBy: ".") |
46 | | - |
47 | | - // Verify that the fully qualified name contains at least a type name and default implementation name. |
48 | | - guard typeComponents.count >= 2 else { return } |
49 | | - |
| 43 | + mutating func add(_ childReference: ResolvedTopicReference, to reference: ResolvedTopicReference, originDisplayName: String, originParentSymbol: ResolvedTopicReference?, extendedModuleName: String) throws { |
| 44 | + let fromType: String |
| 45 | + let typeSimpleName: String |
| 46 | + if let originParentSymbol = originParentSymbol, !originParentSymbol.pathComponents.isEmpty { |
| 47 | + // If we have a resolved symbol for the parent of `sourceOrigin`, use that for the names |
| 48 | + fromType = originParentSymbol.pathComponents.joined(separator: ".") |
| 49 | + typeSimpleName = originParentSymbol.pathComponents.last! |
| 50 | + } else { |
| 51 | + // If we don't have a resolved `sourceOrigin` parent, fall back to parsing its display name |
| 52 | + |
| 53 | + // Detect the path components of the providing the default implementation. |
| 54 | + let typeComponents = originDisplayName.split(separator: ".") |
| 55 | + |
| 56 | + // Verify that the fully qualified name contains at least a type name and default implementation name. |
| 57 | + guard typeComponents.count >= 2 else { return } |
| 58 | + |
| 59 | + // Get the fully qualified type. |
| 60 | + fromType = typeComponents.dropLast().joined(separator: ".") |
| 61 | + // The name of the type is second to last. |
| 62 | + typeSimpleName = String(typeComponents[typeComponents.count-2]) |
| 63 | + } |
| 64 | + |
50 | 65 | // Create a type with inherited symbols, if needed. |
51 | 66 | if !implementingTypes.keys.contains(reference) { |
52 | 67 | implementingTypes[reference] = Collections() |
53 | 68 | } |
54 | 69 |
|
55 | | - // Get the fully qualified type. |
56 | | - let fromType = typeComponents.dropLast().joined(separator: ".") |
57 | | - |
58 | 70 | // Create a new default implementations provider, if needed. |
59 | 71 | if !implementingTypes[reference]!.inheritedFromTypeName.keys.contains(fromType) { |
60 | | - // The name of the type is second to last. |
61 | | - let typeSimpleName = typeComponents[typeComponents.count-2] |
62 | 72 | implementingTypes[reference]!.inheritedFromTypeName[fromType] = Collections.APICollection(title: "\(typeSimpleName) Implementations", parentReference: reference) |
63 | 73 | } |
64 | 74 |
|
@@ -215,8 +225,12 @@ enum GeneratedDocumentationTopics { |
215 | 225 | let child = context.symbolIndex[relationship.source], |
216 | 226 | // Get the swift extension data |
217 | 227 | let extends = child.symbol?.mixins[SymbolGraph.Symbol.Swift.Extension.mixinKey] as? SymbolGraph.Symbol.Swift.Extension { |
| 228 | + var originParentSymbol: ResolvedTopicReference? = nil |
| 229 | + if let originSymbol = context.symbolIndex[origin.identifier] { |
| 230 | + originParentSymbol = try? symbolsURLHierarchy.parent(of: originSymbol.reference) |
| 231 | + } |
218 | 232 | // Add the inherited symbol to the index. |
219 | | - try inheritanceIndex.add(child.reference, to: parent.reference, originDisplayName: origin.displayName, extendedModuleName: extends.extendedModule) |
| 233 | + try inheritanceIndex.add(child.reference, to: parent.reference, originDisplayName: origin.displayName, originParentSymbol: originParentSymbol, extendedModuleName: extends.extendedModule) |
220 | 234 | } |
221 | 235 | } |
222 | 236 |
|
|
0 commit comments