Skip to content

Commit

Permalink
add the extending module as a related module for extension symbols (#557
Browse files Browse the repository at this point in the history
)

rdar://107729534
  • Loading branch information
QuietMisdreavus authored Apr 21, 2023
1 parent 1d300e7 commit 88d0fd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,8 @@ public struct RenderNodeTranslator: SemanticVisitor {

if let crossImportOverlayModule = symbol.crossImportOverlayModule {
node.metadata.modulesVariants = VariantCollection(defaultValue: [RenderMetadata.Module(name: crossImportOverlayModule.declaringModule, relatedModules: crossImportOverlayModule.bystanderModules)])
} else if let extendedModule = symbol.extendedModule, extendedModule != moduleName.displayName {
node.metadata.modulesVariants = VariantCollection(defaultValue: [RenderMetadata.Module(name: moduleName.displayName, relatedModules: [extendedModule])])
} else {
node.metadata.modulesVariants = VariantCollection(defaultValue: [RenderMetadata.Module(name: moduleName.displayName, relatedModules: nil)]
)
Expand Down
15 changes: 15 additions & 0 deletions Tests/SwiftDocCTests/Rendering/RenderMetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ class RenderMetadataTests: XCTestCase {
XCTAssertEqual(renderNode.metadata.modules?.first?.name, "OverlayTest")
XCTAssertEqual(renderNode.metadata.modules?.first?.relatedModules, ["BaseKit"])
}

func testRendersExtensionSymbolsWithBystanderModules() throws {
let (_, bundle, context) = try testBundleAndContext(copying: "BundleWithRelativePathAmbiguity") { root in
// We don't want the external target to be part of the archive as that is not
// officially supported yet.
try FileManager.default.removeItem(at: root.appendingPathComponent("Dependency.symbols.json"))
}

// Get a translated render node
let node = try context.entity(with: ResolvedTopicReference(bundleIdentifier: "org.swift.docc.example", path: "/documentation/BundleWithRelativePathAmbiguity/Dependency/AmbiguousType", sourceLanguage: .swift))
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference, source: nil)
let renderNode = translator.visit(node.semantic as! Symbol) as! RenderNode
XCTAssertEqual(renderNode.metadata.modules?.first?.name, "BundleWithRelativePathAmbiguity")
XCTAssertEqual(renderNode.metadata.modules?.first?.relatedModules, ["Dependency"])
}

func testEmitsTitleVariantsDuringEncoding() throws {
var metadata = RenderMetadata()
Expand Down

0 comments on commit 88d0fd6

Please sign in to comment.