Skip to content

Commit 75b536c

Browse files
committed
Do not emit relationship sections for variants with no relationships
When an Objective-C symbol has no relationships, do not emit relationships, instead of defaulting to the Swift variant's relationships.
1 parent 5391853 commit 75b536c

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,9 +1159,10 @@ public struct RenderNodeTranslator: SemanticVisitor {
11591159
}
11601160

11611161
node.relationshipSectionsVariants = VariantCollection<[RelationshipsRenderSection]>(
1162-
from: symbol.relationshipsVariants
1163-
) { trait, relationships in
1164-
guard !relationships.groups.isEmpty else {
1162+
from: documentationNode.availableVariantTraits,
1163+
fallbackDefaultValue: []
1164+
) { trait in
1165+
guard let relationships = symbol.relationshipsVariants[trait], !relationships.groups.isEmpty else {
11651166
return []
11661167
}
11671168

Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorSymbolVariantsTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,47 @@ class RenderNodeTranslatorSymbolVariantsTests: XCTestCase {
615615
)
616616
}
617617

618+
func testDoesNotEmitObjectiveCRelationshipsForTopicThatOnlyHasSwiftRelationships() throws {
619+
try assertMultiVariantSymbol(
620+
configureContext: { context, _ in
621+
622+
// Set up an Objective-C title for MyProtocol.
623+
let myFunctionNode = try context.entity(
624+
with: ResolvedTopicReference(
625+
bundleIdentifier: "org.swift.docc.example",
626+
path: "/documentation/MyKit/MyProtocol",
627+
fragment: nil,
628+
sourceLanguage: .swift
629+
)
630+
)
631+
632+
let myProtocol = try XCTUnwrap(myFunctionNode.semantic as? Symbol)
633+
myProtocol.titleVariants[.objectiveC] = "MyProtocol"
634+
},
635+
configureSymbol: { symbol in
636+
symbol.relationshipsVariants[.swift] = makeRelationshipSection(
637+
kind: .inheritedBy,
638+
path: "/documentation/MyKit/MyClass/myFunction()"
639+
)
640+
641+
symbol.relationshipsVariants[.objectiveC] = nil
642+
},
643+
assertOriginalRenderNode: { renderNode in
644+
XCTAssertEqual(renderNode.relationshipSections.count, 1)
645+
let relationshipSection = try XCTUnwrap(renderNode.relationshipSections.first)
646+
XCTAssertEqual(relationshipSection.title, "Inherited By")
647+
648+
XCTAssertEqual(
649+
relationshipSection.identifiers,
650+
["doc://org.swift.docc.example/documentation/MyKit/MyClass/myFunction()"]
651+
)
652+
},
653+
assertAfterApplyingVariant: { renderNode in
654+
XCTAssert(renderNode.relationshipSections.isEmpty)
655+
}
656+
)
657+
}
658+
618659
func testTopicsSectionVariants() throws {
619660
try assertMultiVariantSymbol(
620661
configureContext: { context, reference in

0 commit comments

Comments
 (0)