Skip to content

Commit 34b237a

Browse files
committed
Do not emit See Also sections for variants that have no See Also topics
When an Objective-C symbol has no See Also topics, or when it has empty See Also topic groups, dont' emit a See Also section for it, rather than defaulting to the Swift's variant's See Also topics.
1 parent 1aa5c80 commit 34b237a

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,22 +1350,20 @@ public struct RenderNodeTranslator: SemanticVisitor {
13501350
bundle: bundle,
13511351
renderContext: renderContext,
13521352
renderer: contentRenderer
1353-
) {
1353+
), !seeAlso.references.isEmpty {
13541354
contentCompiler.collectedTopicReferences.append(contentsOf: seeAlso.references)
1355-
seeAlsoSections.append(TaskGroupRenderSection(
1356-
title: seeAlso.title,
1357-
abstract: nil,
1358-
discussion: nil,
1359-
identifiers: seeAlso.references.map { $0.absoluteString },
1360-
generated: true
1361-
))
1355+
seeAlsoSections.append(
1356+
TaskGroupRenderSection(
1357+
title: seeAlso.title,
1358+
abstract: nil,
1359+
discussion: nil,
1360+
identifiers: seeAlso.references.map { $0.absoluteString },
1361+
generated: true
1362+
)
1363+
)
13621364
}
13631365

1364-
if seeAlsoSections.isEmpty {
1365-
return nil
1366-
} else {
1367-
return seeAlsoSections
1368-
}
1366+
return seeAlsoSections
13691367
} ?? .init(defaultValue: [])
13701368

13711369
node.deprecationSummaryVariants = VariantCollection<[RenderBlockContent]?>(

Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,30 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
990990
)
991991
}
992992

993+
func testDoesNotEmitObjectiveCSeeAlsoIfEmpty() throws {
994+
func makeSeeAlsoSection(destination: String) -> SeeAlsoSection {
995+
SeeAlsoSection(content: [
996+
UnorderedList(
997+
ListItem(Paragraph(Link(destination: destination)))
998+
)
999+
])
1000+
}
1001+
1002+
try assertMultiVariantSymbol(
1003+
configureSymbol: { symbol in
1004+
symbol.seeAlsoVariants[.swift] = makeSeeAlsoSection(
1005+
destination: "doc://org.swift.docc.example/documentation/MyKit/MyProtocol"
1006+
)
1007+
},
1008+
assertOriginalRenderNode: { renderNode in
1009+
XCTAssertEqual(renderNode.seeAlsoSections.count, 2)
1010+
},
1011+
assertAfterApplyingVariant: { renderNode in
1012+
XCTAssert(renderNode.seeAlsoSections.isEmpty)
1013+
}
1014+
)
1015+
}
1016+
9931017
func testDeprecationSummaryVariants() throws {
9941018
try assertMultiVariantSymbol(
9951019
configureSymbol: { symbol in

0 commit comments

Comments
 (0)