Skip to content

Commit 61775b4

Browse files
Fix regression where DocC no longer emits warnings for unresolved links. (#774)
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 efcc793 commit 61775b4

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
@@ -599,7 +599,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
599599

600600
var problems = resolver.problems
601601

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

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4030,6 +4030,55 @@ let expected = """
40304030
let range = try XCTUnwrap(problem.diagnostic.range)
40314031
XCTAssertEqual(start..<end, range)
40324032
}
4033+
4034+
func testUnresolvedLinkWarnings() throws {
4035+
var (_, _, context) = try testBundleAndContext(copying: "TestBundle") { url in
4036+
let extensionFile = """
4037+
# ``SideKit``
4038+
4039+
myFunction abstract
4040+
4041+
## Overview
4042+
4043+
This is unresolvable: <doc:Does-Not-Exist>.
4044+
4045+
## Topics
4046+
4047+
- <doc:NonExistingDoc>
4048+
4049+
"""
4050+
let fileURL = url.appendingPathComponent("documentation").appendingPathComponent("myFunction.md")
4051+
try extensionFile.write(to: fileURL, atomically: true, encoding: .utf8)
4052+
}
4053+
var problems = context.diagnosticEngine.problems
4054+
var linkResolutionProblems = problems.filter { $0.diagnostic.source?.relativePath.hasSuffix("myFunction.md") == true }
4055+
XCTAssertEqual(linkResolutionProblems.count, 3)
4056+
var problem = try XCTUnwrap(linkResolutionProblems.last)
4057+
XCTAssertEqual(problem.diagnostic.summary, "\'NonExistingDoc\' doesn\'t exist at \'/SideKit\'")
4058+
(_, _, context) = try testBundleAndContext(copying: "BookLikeContent") { url in
4059+
let extensionFile = """
4060+
# My Article
4061+
4062+
Abstract
4063+
4064+
## Overview
4065+
4066+
Overview
4067+
4068+
## Topics
4069+
4070+
- <doc:NonExistingDoc>
4071+
4072+
"""
4073+
let fileURL = url.appendingPathComponent("MyArticle.md")
4074+
try extensionFile.write(to: fileURL, atomically: true, encoding: .utf8)
4075+
}
4076+
problems = context.diagnosticEngine.problems
4077+
linkResolutionProblems = problems.filter { $0.diagnostic.source?.relativePath.hasSuffix("MyArticle.md") == true }
4078+
XCTAssertEqual(linkResolutionProblems.count, 1)
4079+
problem = try XCTUnwrap(linkResolutionProblems.last)
4080+
XCTAssertEqual(problem.diagnostic.summary, "\'NonExistingDoc\' doesn\'t exist at \'/BestBook/MyArticle\'")
4081+
}
40334082
}
40344083

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

0 commit comments

Comments
 (0)