Skip to content

Commit 49c6d92

Browse files
authored
Don't suggest bundle name as possible replacement for symbol links (#900)
rdar://125964139
1 parent bfbc983 commit 49c6d92

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ extension PathHierarchy {
115115
}
116116
}
117117
}
118-
let topLevelNames = Set(modules.map(\.name) + [articlesContainer.name, tutorialContainer.name])
118+
let topLevelNames = Set(modules.map(\.name) + (onlyFindSymbols ? [] : [articlesContainer.name, tutorialContainer.name]))
119119

120120
if isAbsolute, FeatureFlags.current.isExperimentalLinkHierarchySerializationEnabled {
121121
throw Error.moduleNotFound(

Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,32 @@ class PathHierarchyTests: XCTestCase {
13201320
XCTAssert(overloadedProtocolMethod.symbol?.identifier.precise.hasSuffix(SymbolGraph.Symbol.overloadGroupIdentifierSuffix) == true)
13211321
}
13221322

1323+
func testDoesNotSuggestBundleNameForSymbolLink() throws {
1324+
let exampleDocumentation = Folder(name: "Something.docc", content: [
1325+
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(moduleName: "ModuleName")),
1326+
1327+
InfoPlist(displayName: "ModuleNaem"), // The bundle name is intentionally misspelled.
1328+
1329+
// The symbol link in the header is intentionally misspelled.
1330+
TextFile(name: "root.md", utf8Content: """
1331+
# ``ModuleNaem``
1332+
1333+
A documentation extension file with a misspelled link that happens to match the, also misspelled, bundle name.
1334+
"""),
1335+
])
1336+
let catalogURL = try exampleDocumentation.write(inside: createTemporaryDirectory())
1337+
let (_, _, context) = try loadBundle(from: catalogURL)
1338+
let tree = context.linkResolver.localResolver.pathHierarchy
1339+
1340+
// This link is intentionally misspelled
1341+
try assertPathRaisesErrorMessage("ModuleNaem", in: tree, context: context, expectedErrorMessage: "Can't resolve 'ModuleNaem'") { errorInfo in
1342+
XCTAssertEqual(errorInfo.solutions.map(\.summary), ["Replace 'ModuleNaem' with 'ModuleName'"])
1343+
}
1344+
1345+
let linkProblem = try XCTUnwrap(context.problems.first(where: { $0.diagnostic.summary == "No symbol matched 'ModuleNaem'. Can't resolve 'ModuleNaem'."}))
1346+
XCTAssertEqual(linkProblem.possibleSolutions.map(\.summary), ["Replace 'ModuleNaem' with 'ModuleName'"])
1347+
}
1348+
13231349
func testSymbolsWithSameNameAsModule() throws {
13241350
let (_, context) = try testBundleAndContext(named: "SymbolsWithSameNameAsModule")
13251351
let tree = context.linkResolver.localResolver.pathHierarchy

0 commit comments

Comments
 (0)