Skip to content

Commit f730fe5

Browse files
committed
Allow processing symbol graphs of unknown languages
DocC currently has a set of 'known' programming languages for which it has display names, and loading symbol graphs currently requires the symbols' language to be known by DocC. There's no reason to not process allow processing symbols of unknown language though, and this fix makes DocC more flexible in that respect. The end-to-end compilation flow works fine with the change.
1 parent d991842 commit f730fe5

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolReference.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ extension UnifiedSymbolGraph.Symbol {
182182
// Adding a dedicated SymbolKit API for this purpose is tracked
183183
// with github.com/apple/swift-docc-symbolkit/issues/32 and rdar://85982095.
184184
return Set(
185-
pathComponents.keys.compactMap { selector in
186-
return SourceLanguage(knownLanguageIdentifier: selector.interfaceLanguage)
185+
pathComponents.keys.map { selector in
186+
SourceLanguage(knownLanguageIdentifier: selector.interfaceLanguage)
187+
?? SourceLanguage(id: selector.interfaceLanguage)
187188
}
188189
)
189190
}

Tests/SwiftDocCTests/Infrastructure/SymbolReferenceTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,52 @@ class SymbolReferenceTests: XCTestCase {
216216
]
217217
)
218218
}
219+
220+
func testKnownSourceLanguagesOfUnifiedGraphSymbol() {
221+
let module = SymbolGraph.Module(
222+
name: "os",
223+
platform: SymbolGraph.Platform()
224+
)
225+
226+
let unifiedSymbol = UnifiedSymbolGraph.Symbol(
227+
fromSingleSymbol: makeSymbol(interfaceLanguage: "swift"),
228+
module: module,
229+
isMainGraph: true
230+
)
231+
232+
unifiedSymbol.mergeSymbol(
233+
symbol: makeSymbol(interfaceLanguage: "c"),
234+
module: module,
235+
isMainGraph: true
236+
)
237+
238+
XCTAssertEqual(unifiedSymbol.sourceLanguages.map(\.id).sorted(), ["occ", "swift"])
239+
}
240+
241+
func testUnknownSourceLanguagesOfUnifiedGraphSymbol() {
242+
let module = SymbolGraph.Module(
243+
name: "os",
244+
platform: SymbolGraph.Platform()
245+
)
246+
247+
let unifiedSymbol = UnifiedSymbolGraph.Symbol(
248+
fromSingleSymbol: makeSymbol(interfaceLanguage: "unknown-language"),
249+
module: module,
250+
isMainGraph: true
251+
)
252+
253+
XCTAssertEqual(unifiedSymbol.sourceLanguages.map(\.id).sorted(), ["unknown-language"])
254+
}
255+
256+
private func makeSymbol(interfaceLanguage: String) -> SymbolGraph.Symbol {
257+
SymbolGraph.Symbol(
258+
identifier: .init(precise: "abcd", interfaceLanguage: interfaceLanguage),
259+
names: .init(title: "abcd", navigator: nil, subHeading: nil, prose: nil),
260+
pathComponents: ["test", "abcd"],
261+
docComment: nil,
262+
accessLevel: .init(rawValue: "public"),
263+
kind: .init(parsedIdentifier: .module, displayName: "Framework"),
264+
mixins: [:]
265+
)
266+
}
219267
}

0 commit comments

Comments
 (0)