Skip to content

Commit 49bbf7b

Browse files
drop uncurated symbols from the navigator index (#890)
rdar://125855186
1 parent 49c6d92 commit 49bbf7b

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,21 @@ public class NavigatorIndex {
358358
default: self = .article
359359
}
360360
}
361-
361+
362+
/// Whether this page kind references a symbol.
363+
var isSymbolKind: Bool {
364+
switch self {
365+
case .root, .article, .tutorial, .section, .learn, .overview, .resources, .framework,
366+
.buildSetting, .sampleCode, .languageGroup, .container, .groupMarker:
367+
return false
368+
case .symbol, .class, .structure, .protocol, .enumeration, .function, .extension,
369+
.localVariable, .globalVariable, .typeAlias, .associatedType, .operator, .macro,
370+
.union, .enumerationCase, .initializer, .instanceMethod, .instanceProperty,
371+
.instanceVariable, .subscript, .typeMethod, .typeProperty, .propertyListKey,
372+
.httpRequest, .dictionarySymbol, .propertyListKeyReference, .namespace:
373+
return true
374+
}
375+
}
362376
}
363377

364378
// MARK: - Read Navigator Tree
@@ -918,7 +932,11 @@ extension NavigatorIndex {
918932

919933
// The rest have no parent, so they need to be under the root.
920934
for nodeID in pendingUncuratedReferences {
921-
if let node = identifierToNode[nodeID] {
935+
// Don't add symbol nodes to the root; if they have been dropped by automatic
936+
// curation, then they should not be in the navigator. In addition, treat unknown
937+
// page types as symbol nodes on the assumption that an unknown page type is a
938+
// symbol kind added in a future version of Swift-DocC.
939+
if let node = identifierToNode[nodeID], PageType(rawValue: node.item.pageType)?.isSymbolKind == false {
922940

923941
// If an uncurated page has been curated in another language, don't add it to the top-level.
924942
if curatedReferences.contains(where: { curatedNodeID in

Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,16 +1629,51 @@ Root
16291629
for: "OverloadedSymbols",
16301630
bundleIdentifier: "com.shapes.ShapeKit")
16311631

1632-
let protocolID = try XCTUnwrap(navigatorIndex.id(for: "/documentation/shapekit/overloadedprotocol", with: .swift))
1633-
let protocolNode = try XCTUnwrap(search(node: navigatorIndex.navigatorTree.root) { $0.id == protocolID })
1634-
XCTAssertEqual(protocolNode.children.map(\.item.title), [
1635-
"Instance Methods",
1636-
"func fourthTestMemberName(test:)",
1637-
])
1638-
1639-
let overloadGroupID = try XCTUnwrap(navigatorIndex.id(for: "/documentation/shapekit/overloadedprotocol/fourthtestmembername(test:)-9b6be", with: .swift))
1640-
let overloadGroupNode = try XCTUnwrap(search(node: navigatorIndex.navigatorTree.root) { $0.id == overloadGroupID })
1641-
XCTAssert(overloadGroupNode.children.isEmpty)
1632+
XCTAssertEqual(
1633+
navigatorIndex.navigatorTree.root.dumpTree(),
1634+
"""
1635+
[Root]
1636+
┗╸Swift
1637+
┗╸ShapeKit
1638+
┣╸Protocols
1639+
┣╸OverloadedProtocol
1640+
┃ ┣╸Instance Methods
1641+
┃ ┗╸func fourthTestMemberName(test:)
1642+
┣╸Structures
1643+
┣╸OverloadedByCaseStruct
1644+
┃ ┣╸Instance Properties
1645+
┃ ┣╸let ThirdTestMemberName: Int
1646+
┃ ┣╸let thirdTestMemberNamE: Int
1647+
┃ ┣╸let thirdTestMemberName: Int
1648+
┃ ┗╸let thirdtestMemberName: Int
1649+
┣╸OverloadedParentStruct
1650+
┃ ┣╸Type Properties
1651+
┃ ┗╸static let fifthTestMember: Int
1652+
┣╸OverloadedStruct
1653+
┃ ┣╸Instance Properties
1654+
┃ ┣╸let secondTestMemberName: Int
1655+
┃ ┣╸Type Properties
1656+
┃ ┗╸static let secondTestMemberName: Int
1657+
┣╸RegularParent
1658+
┃ ┣╸Instance Properties
1659+
┃ ┣╸let firstMember: Int
1660+
┃ ┣╸Instance Methods
1661+
┃ ┣╸func secondMember(first: Int, second: String)
1662+
┃ ┣╸Type Properties
1663+
┃ ┣╸static let thirdMember: Int
1664+
┃ ┣╸Enumerations
1665+
┃ ┗╸RegularParent.FourthMember
1666+
┣╸overloadedparentstruct
1667+
┃ ┣╸Instance Properties
1668+
┃ ┗╸let fifthTestMember: Int
1669+
┣╸Enumerations
1670+
┗╸OverloadedEnum
1671+
┣╸Enumeration Cases
1672+
┣╸case firstTestMemberName(String)
1673+
┣╸Instance Methods
1674+
┗╸func firstTestMemberName(_:)
1675+
"""
1676+
)
16421677
}
16431678

16441679
func generatedNavigatorIndex(for testBundleName: String, bundleIdentifier: String) throws -> NavigatorIndex {

0 commit comments

Comments
 (0)