Skip to content

Commit 121c159

Browse files
committed
Add DiagnosticNote to make warnings more actionable
Enhance the "symbols with @TechnologyRoot pages" warning by adding DiagnosticNote entries that point to the symbol graph files causing the multiple roots issue. This helps developers identify exactly which symbol graph files are part of the problem. Also update the test to verify the diagnostic notes are present. Based on PR review feedback.
1 parent 4ec94c0 commit 121c159

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,17 @@ public class DocumentationContext {
24332433
// This is an unsupported setup that creates multiple roots in the documentation hierarchy
24342434
if !rootModules.isEmpty && !rootPageArticles.isEmpty {
24352435
let problems = rootPageArticles.map { rootPageArticle -> Problem in
2436+
// Create notes pointing to symbol graph files that are causing the multiple roots issue
2437+
let symbolGraphNotes: [DiagnosticNote] = bundle.symbolGraphURLs.map { symbolGraphURL in
2438+
let fileName = symbolGraphURL.lastPathComponent
2439+
let zeroRange = SourceLocation(line: 1, column: 1, source: nil)..<SourceLocation(line: 1, column: 1, source: nil)
2440+
return DiagnosticNote(
2441+
source: symbolGraphURL,
2442+
range: zeroRange,
2443+
message: "Symbol graph file '\(fileName)' creates a module root"
2444+
)
2445+
}
2446+
24362447
let diagnostic = Diagnostic(
24372448
source: rootPageArticle.source,
24382449
severity: .warning,
@@ -2442,7 +2453,8 @@ public class DocumentationContext {
24422453
explanation: """
24432454
When documentation contains symbols (from symbol graph files), @TechnologyRoot directives create an unsupported setup with multiple roots in the documentation hierarchy.
24442455
Remove the @TechnologyRoot directive so that this page is treated as an article under the module.
2445-
"""
2456+
""",
2457+
notes: symbolGraphNotes
24462458
)
24472459

24482460
guard let range = rootPageArticle.value.metadata?.technologyRoot?.originalMarkup.range else {

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContext+RootPageTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ class DocumentationContext_RootPageTests: XCTestCase {
257257
let solution = try XCTUnwrap(problem.possibleSolutions.first)
258258
XCTAssertEqual(solution.summary, "Remove the 'TechnologyRoot' directive")
259259
XCTAssertEqual(solution.replacements.count, 1)
260+
261+
// Verify that diagnostic notes point to the symbol graph file
262+
XCTAssertEqual(problem.diagnostic.notes.count, 1, "Should have a note pointing to the symbol graph file")
263+
let note = try XCTUnwrap(problem.diagnostic.notes.first)
264+
XCTAssertTrue(note.source.lastPathComponent.hasSuffix(".symbols.json"), "Note should point to a symbol graph file")
265+
XCTAssertTrue(note.message.contains("Symbol graph file"), "Note should mention symbol graph file")
260266
}
261267
}
262268

0 commit comments

Comments
 (0)