Skip to content

Commit 4d71460

Browse files
Fix regression where DocC no longer emits warnings for unresolved links. (#775)
rdar://119603319 Emit warnings for unresolved links inside articles. Regression was presumably introduced in da16aa9. When the node is an article we don’t want to check the offset because is not a source file. Before the fix, the logic was removing all problems because it wouldn’t contain an offset, falling through the else condition. Added test to make sure that problems are generated when an article or symbol extension file contains unresolved links.
1 parent 062fbf5 commit 4d71460

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
623623

624624
var problems = resolver.problems
625625

626-
if case .sourceCode(_, let offset) = doc.source {
626+
if case .sourceCode(_, let offset) = doc.source, documentationNode.kind.isSymbol {
627627
// Offset all problem ranges by the start location of the
628628
// source comment in the context of the complete file.
629629
if let docRange = offset {

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3981,6 +3981,55 @@ let expected = """
39813981
let range = try XCTUnwrap(problem.diagnostic.range)
39823982
XCTAssertEqual(start..<end, range)
39833983
}
3984+
3985+
func testUnresolvedLinkWarnings() throws {
3986+
var (_, _, context) = try testBundleAndContext(copying: "TestBundle") { url in
3987+
let extensionFile = """
3988+
# ``SideKit``
3989+
3990+
myFunction abstract
3991+
3992+
## Overview
3993+
3994+
This is unresolvable: <doc:Does-Not-Exist>.
3995+
3996+
## Topics
3997+
3998+
- <doc:NonExistingDoc>
3999+
4000+
"""
4001+
let fileURL = url.appendingPathComponent("documentation").appendingPathComponent("myFunction.md")
4002+
try extensionFile.write(to: fileURL, atomically: true, encoding: .utf8)
4003+
}
4004+
var problems = context.diagnosticEngine.problems
4005+
var linkResolutionProblems = problems.filter { $0.diagnostic.source?.relativePath.hasSuffix("myFunction.md") == true }
4006+
XCTAssertEqual(linkResolutionProblems.count, 3)
4007+
var problem = try XCTUnwrap(linkResolutionProblems.last)
4008+
XCTAssertEqual(problem.diagnostic.summary, "\'NonExistingDoc\' doesn\'t exist at \'/SideKit\'")
4009+
(_, _, context) = try testBundleAndContext(copying: "BookLikeContent") { url in
4010+
let extensionFile = """
4011+
# My Article
4012+
4013+
Abstract
4014+
4015+
## Overview
4016+
4017+
Overview
4018+
4019+
## Topics
4020+
4021+
- <doc:NonExistingDoc>
4022+
4023+
"""
4024+
let fileURL = url.appendingPathComponent("MyArticle.md")
4025+
try extensionFile.write(to: fileURL, atomically: true, encoding: .utf8)
4026+
}
4027+
problems = context.diagnosticEngine.problems
4028+
linkResolutionProblems = problems.filter { $0.diagnostic.source?.relativePath.hasSuffix("MyArticle.md") == true }
4029+
XCTAssertEqual(linkResolutionProblems.count, 1)
4030+
problem = try XCTUnwrap(linkResolutionProblems.last)
4031+
XCTAssertEqual(problem.diagnostic.summary, "\'NonExistingDoc\' doesn\'t exist at \'/BestBook/MyArticle\'")
4032+
}
39844033
}
39854034

39864035
func assertEqualDumps(_ lhs: String, _ rhs: String, file: StaticString = #file, line: UInt = #line) {

0 commit comments

Comments
 (0)