Skip to content

Commit e15f4e1

Browse files
authored
Store all source languages in documentation node (#1326)
The documentation node stores the list of source languages that the node is available in. Previously, this information was being stored in the render node as a set containing the singular source language of the node. This worked in the past when Swift was the only relevant language, but `sourceLanguage` is now relegated to a backwards-compatible property that queries `sourceLanguages` for the value it returns. This patch updates the documentation node constructors to correctly store the set of source languages in the node. rdar://163034867
1 parent b27288d commit e15f4e1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Sources/SwiftDocC/Model/DocumentationNode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public struct DocumentationNode {
238238
Symbol.Overloads(references: [], displayIndex: overloadData.overloadGroupIndex)
239239
})
240240

241-
var languages = Set([reference.sourceLanguage])
241+
var languages = reference.sourceLanguages
242242
var operatingSystemName = platformName.map({ Set([$0]) }) ?? []
243243

244244
for (_, symbolAvailability) in symbolAvailabilityVariants.allValues {
@@ -776,7 +776,7 @@ public struct DocumentationNode {
776776

777777
let symbolAvailability = symbol.mixins[SymbolGraph.Symbol.Availability.mixinKey] as? SymbolGraph.Symbol.Availability
778778

779-
var languages = Set([reference.sourceLanguage])
779+
var languages = reference.sourceLanguages
780780
var operatingSystemName = platformName.map({ Set([$0]) }) ?? []
781781

782782
let availabilityDomains = symbolAvailability?.availability.compactMap({ $0.domain?.rawValue })
@@ -859,7 +859,7 @@ public struct DocumentationNode {
859859
self.semantic = article
860860
self.sourceLanguage = reference.sourceLanguage
861861
self.name = .conceptual(title: article.title?.title ?? "")
862-
self.availableSourceLanguages = [reference.sourceLanguage]
862+
self.availableSourceLanguages = reference.sourceLanguages
863863
self.docChunks = [DocumentationChunk(source: .documentationExtension, markup: articleMarkup)]
864864
self.markup = articleMarkup
865865
self.isVirtual = false

Tests/SwiftDocCTests/Model/DocumentationNodeTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,27 @@ class DocumentationNodeTests: XCTestCase {
7676
XCTAssertEqual(DocumentationNode.symbolKind(for: .typeConstant), .typeProperty)
7777
XCTAssertEqual(DocumentationNode.symbolKind(for: .object), .dictionary)
7878
}
79+
80+
func testWithMultipleSourceLanguages() throws {
81+
let sourceLanguages: Set<SourceLanguage> = [.swift, .objectiveC]
82+
// Test if articles contain all available source languages
83+
let article = Article(markup: Document(parsing: "# Title", options: []), metadata: nil, redirects: nil, options: [:])
84+
let articleNode = try DocumentationNode(
85+
reference: ResolvedTopicReference(bundleID: "org.swift.docc", path: "/blah", sourceLanguages: sourceLanguages),
86+
article: article
87+
)
88+
XCTAssertEqual(articleNode.availableSourceLanguages, sourceLanguages)
89+
90+
// Test if symbols contain all available source languages
91+
let symbol = makeSymbol(id: "blah", kind: .class, pathComponents: ["blah"])
92+
let symbolNode = DocumentationNode(
93+
reference: ResolvedTopicReference(bundleID: "org.swift.docc", path: "/blah", sourceLanguages: sourceLanguages),
94+
symbol: symbol,
95+
platformName: nil,
96+
moduleReference: ResolvedTopicReference(bundleID: "org.swift.docc", path: "/blah", sourceLanguages: sourceLanguages),
97+
article: nil,
98+
engine: DiagnosticEngine()
99+
)
100+
XCTAssertEqual(symbolNode.availableSourceLanguages, sourceLanguages)
101+
}
79102
}

0 commit comments

Comments
 (0)