Skip to content

Commit

Permalink
removes logic duplicated in SymbolKit
Browse files Browse the repository at this point in the history
 - prefer SymbolKit for this logic
  • Loading branch information
heckj committed Dec 2, 2024
1 parent ff4ba14 commit 9fa5bab
Showing 1 changed file with 2 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct SymbolGraphLoader {

symbolGraphTransformer?(&symbolGraph)

let (moduleName, isMainSymbolGraph) = Self.moduleNameFor(symbolGraph, at: symbolGraphURL)
let (moduleName, isMainSymbolGraph) = GraphCollector.moduleNameFor(symbolGraph, at: symbolGraphURL)
// If the bundle provides availability defaults add symbol availability data.
self.addDefaultAvailability(to: &symbolGraph, moduleName: moduleName)

Expand Down Expand Up @@ -193,7 +193,7 @@ struct SymbolGraphLoader {
private func loadSymbolGraph(at url: URL) throws -> (SymbolGraph, isMainSymbolGraph: Bool) {
// This is a private method, the `url` key is known to exist
var symbolGraph = symbolGraphs[url]!
let (moduleName, isMainSymbolGraph) = Self.moduleNameFor(symbolGraph, at: url)
let (moduleName, isMainSymbolGraph) = GraphCollector.moduleNameFor(symbolGraph, at: url)

if !isMainSymbolGraph && symbolGraph.module.bystanders == nil {
// If this is an extending another module, change the module name to match the extended module.
Expand Down Expand Up @@ -340,31 +340,7 @@ struct SymbolGraphLoader {

return fileName.split(separator: "@", maxSplits: 1).last.map({ String($0) })
}

/// Returns the module name of a symbol graph based on the JSON data and file name.
///
/// Useful during decoding the symbol graphs to implement the correct name logic starting with the module name in the JSON.
private static func moduleNameFor(_ symbolGraph: SymbolGraph, at url: URL) -> (String, Bool) {
let isMainSymbolGraph = !url.lastPathComponent.contains("@")

let moduleName: String
if isMainSymbolGraph || symbolGraph.module.bystanders != nil {
// For main symbol graphs, get the module name from the symbol graph's data

// When bystander modules are present, the symbol graph is a cross-import overlay, and
// we need to preserve the original module name to properly render it. It is still
// kept with the extension symbols, due to the merging behavior of UnifiedSymbolGraph.
moduleName = symbolGraph.module.name
} else {
// For extension symbol graphs, derive the extended module's name from the file name.
//
// The per-symbol `extendedModule` value is the same as the main module for most symbols, so it's not a good way to find the name
// of the module that was extended (rdar://63200368).
moduleName = SymbolGraphLoader.moduleNameFor(url)!
}
return (moduleName, isMainSymbolGraph)
}

private static func applyWorkaroundFor139305015(to symbolGraph: inout SymbolGraph) {
guard symbolGraph.symbols.values.mapFirst(where: { SourceLanguage(id: $0.identifier.interfaceLanguage) }) == .objectiveC else {
return
Expand Down

0 comments on commit 9fa5bab

Please sign in to comment.