Skip to content

Commit ccf26c9

Browse files
authored
Try finding full path component before the parsed path component name (#485)
rdar://101212257
1 parent e9b62ce commit ccf26c9

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ struct PathHierarchy {
378378
/// - Returns: The child disambiguation tree and path component.
379379
private func findChildTree(node: inout Node, remaining: ArraySlice<PathComponent>) throws -> (DisambiguationTree, PathComponent) {
380380
var pathComponent = remaining.first!
381-
if let match = node.children[pathComponent.name] {
382-
return (match, pathComponent)
383-
} else if let match = node.children[pathComponent.full] {
381+
if let match = node.children[pathComponent.full] {
384382
// The path component parsing may treat dash separated words as disambiguation information.
385383
// If the parsed name didn't match, also try the original.
386384
pathComponent.kind = nil
387385
pathComponent.hash = nil
388386
return (match, pathComponent)
387+
} else if let match = node.children[pathComponent.name] {
388+
return (match, pathComponent)
389389
} else {
390390
if node.name == pathComponent.name || node.name == pathComponent.full, let parent = node.parent {
391391
// When multiple path components in a row have the same name it's possible that the search started at a node that's

Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,47 @@ class PathHierarchyTests: XCTestCase {
11351135
}
11361136
}
11371137

1138+
func testArticleWithDisambiguationLookingName() throws {
1139+
try XCTSkipUnless(LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver)
1140+
let exampleDocumentation = Folder(name: "MyKit.docc", content: [
1141+
CopyOfFile(original: Bundle.module.url(forResource: "BaseKit.symbols", withExtension: "json", subdirectory: "Test Resources")!),
1142+
InfoPlist(displayName: "BaseKit", identifier: "com.test.BaseKit"),
1143+
TextFile(name: "basekit.md", utf8Content: """
1144+
# ``BaseKit``
1145+
1146+
Curate an article that look like a disambiguated symbol
1147+
1148+
## Topics
1149+
1150+
- <doc:OtherStruct>
1151+
- <doc:OtherStruct-abcd>
1152+
"""),
1153+
TextFile(name: "OtherStruct-abcd.md", utf8Content: """
1154+
# Some article
1155+
1156+
An article with a file name that resembles a disambiguated symbol name.
1157+
"""),
1158+
])
1159+
let tempURL = try createTemporaryDirectory()
1160+
let bundleURL = try exampleDocumentation.write(inside: tempURL)
1161+
1162+
do {
1163+
let (_, _, context) = try loadBundle(from: bundleURL)
1164+
XCTAssert(context.problems.isEmpty, "Unexpected problems: \(context.problems.map(\.localizedDescription))")
1165+
1166+
let tree = try XCTUnwrap(context.hierarchyBasedLinkResolver?.pathHierarchy)
1167+
1168+
let baseKitID = try tree.find(path: "/BaseKit", onlyFindSymbols: true)
1169+
1170+
XCTAssertEqual(try tree.findSymbol(path: "OtherStruct", parent: baseKitID).identifier.precise, "s:7BaseKit11OtherStructV")
1171+
1172+
let articleID = try tree.find(path: "OtherStruct-abcd", parent: baseKitID, onlyFindSymbols: false)
1173+
let articleNode = try XCTUnwrap(tree.lookup[articleID])
1174+
XCTAssertNil(articleNode.symbol)
1175+
XCTAssertEqual(articleNode.name, "OtherStruct-abcd")
1176+
}
1177+
}
1178+
11381179
func testPartialSymbolGraphPaths() throws {
11391180
try XCTSkipUnless(LinkResolutionMigrationConfiguration.shouldUseHierarchyBasedLinkResolver)
11401181
let symbolPaths = [

0 commit comments

Comments
 (0)