Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Don't suggest bundle name as possible replacement for symbol links (#900) #902

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extension PathHierarchy {
}
}
}
let topLevelNames = Set(modules.map(\.name) + [articlesContainer.name, tutorialContainer.name])
let topLevelNames = Set(modules.map(\.name) + (onlyFindSymbols ? [] : [articlesContainer.name, tutorialContainer.name]))

if isAbsolute, FeatureFlags.current.isExperimentalLinkHierarchySerializationEnabled {
throw Error.moduleNotFound(
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,32 @@ class PathHierarchyTests: XCTestCase {
}
}

func testDoesNotSuggestBundleNameForSymbolLink() throws {
let exampleDocumentation = Folder(name: "Something.docc", content: [
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(moduleName: "ModuleName")),

InfoPlist(displayName: "ModuleNaem"), // The bundle name is intentionally misspelled.

// The symbol link in the header is intentionally misspelled.
TextFile(name: "root.md", utf8Content: """
# ``ModuleNaem``

A documentation extension file with a misspelled link that happens to match the, also misspelled, bundle name.
"""),
])
let catalogURL = try exampleDocumentation.write(inside: createTemporaryDirectory())
let (_, _, context) = try loadBundle(from: catalogURL)
let tree = context.linkResolver.localResolver.pathHierarchy

// This link is intentionally misspelled
try assertPathRaisesErrorMessage("ModuleNaem", in: tree, context: context, expectedErrorMessage: "Can't resolve 'ModuleNaem'") { errorInfo in
XCTAssertEqual(errorInfo.solutions.map(\.summary), ["Replace 'ModuleNaem' with 'ModuleName'"])
}

let linkProblem = try XCTUnwrap(context.problems.first(where: { $0.diagnostic.summary == "No symbol matched 'ModuleNaem'. Can't resolve 'ModuleNaem'."}))
XCTAssertEqual(linkProblem.possibleSolutions.map(\.summary), ["Replace 'ModuleNaem' with 'ModuleName'"])
}

func testSymbolsWithSameNameAsModule() throws {
let (_, context) = try testBundleAndContext(named: "SymbolsWithSameNameAsModule")
let tree = context.linkResolver.localResolver.pathHierarchy
Expand Down