Skip to content

Commit 037f0bc

Browse files
Fix bug where symbols with display names would get the framework name show up twice in the avaialbility badges. (#922)
When a framework had a display name different to the top-level symbol name, both variations would appear as availability badges in the symbols that were declared in extensions of that same framework, resulting in odd availability information. rdar://126713717
1 parent 2809e81 commit 037f0bc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,8 @@ public struct RenderNodeTranslator: SemanticVisitor {
12351235
from: symbol.extendedModuleVariants,
12361236
transform: { (_, value) in
12371237
let relatedModules: [String]?
1238-
if value != moduleName.displayName {
1238+
// Don't add the module name of extensions made in the compiled module.
1239+
if (value != moduleName.displayName) && (value != moduleName.symbolName) {
12391240
relatedModules = [value]
12401241
} else {
12411242
relatedModules = nil

Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,7 @@ Document
30453045

30463046
let moduleReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/MyKit", sourceLanguage: .swift)
30473047
let protocolReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/MyKit/MyProtocol", sourceLanguage: .swift)
3048+
let functionReference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/MyKit/MyClass/myFunction()", sourceLanguage: .swift)
30483049

30493050
// Verify the MyKit module
30503051

@@ -3098,6 +3099,17 @@ Document
30983099
for moduleVariant in protocolRenderNode.metadata.modulesVariants.variants {
30993100
XCTAssertEqual(moduleVariant.patch.description, "My custom conceptual name")
31003101
}
3102+
3103+
// Verify the MyFunction node
3104+
3105+
let functionNode = try context.entity(with: functionReference)
3106+
let functionSymbol = try XCTUnwrap(functionNode.semantic as? Symbol)
3107+
translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: functionNode.reference, source: nil)
3108+
let functionRenderNode = try XCTUnwrap(translator.visit(functionSymbol) as? RenderNode)
3109+
XCTAssertTrue(functionRenderNode.metadata.modulesVariants.variants.isEmpty)
3110+
// Test that the symbol name `MyKit` is not added as a related module.
3111+
XCTAssertNil((functionRenderNode.metadata.modulesVariants.defaultValue!.first!.relatedModules))
3112+
XCTAssertTrue(functionRenderNode.metadata.extendedModuleVariants.variants.isEmpty)
31013113
}
31023114

31033115
/// Tests that we correctly resolve links in automatic inherited API Collections.

0 commit comments

Comments
 (0)