Skip to content

Commit 35edc36

Browse files
committed
Simplify providing data to symbol graph loader
1 parent f694cad commit 35edc36

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ public class DocumentationContext {
20232023
discoveryGroup.async(queue: discoveryQueue) { [unowned self] in
20242024
symbolGraphLoader = SymbolGraphLoader(
20252025
bundle: bundle,
2026-
dataLoader: { url, _ in try self.dataProvider.contents(of: url) },
2026+
dataProvider: dataProvider,
20272027
symbolGraphTransformer: configuration.convertServiceConfiguration.symbolGraphTransformer
20282028
)
20292029

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@ struct SymbolGraphLoader {
1919
private(set) var symbolGraphs: [URL: SymbolKit.SymbolGraph] = [:]
2020
private(set) var unifiedGraphs: [String: SymbolKit.UnifiedSymbolGraph] = [:]
2121
private(set) var graphLocations: [String: [SymbolKit.GraphCollector.GraphKind]] = [:]
22-
// FIXME: After 6.2, when we no longer have `DocumentationContextDataProvider` we can simply this code to not use a closure to read data.
23-
private var dataLoader: (URL, DocumentationBundle) throws -> Data
24-
private var bundle: DocumentationBundle
25-
private var symbolGraphTransformer: ((inout SymbolGraph) -> ())? = nil
22+
private let dataProvider: any DataProvider
23+
private let bundle: DocumentationBundle
24+
private let symbolGraphTransformer: ((inout SymbolGraph) -> ())?
2625

2726
/// Creates a new symbol graph loader
2827
/// - Parameters:
2928
/// - bundle: The documentation bundle from which to load symbol graphs.
30-
/// - dataLoader: A closure that the loader uses to read symbol graph data.
29+
/// - dataProvider: A provider that the loader uses to read symbol graph data.
3130
/// - symbolGraphTransformer: An optional closure that transforms the symbol graph after the loader decodes it.
3231
init(
3332
bundle: DocumentationBundle,
34-
dataLoader: @escaping (URL, DocumentationBundle) throws -> Data,
33+
dataProvider: any DataProvider,
3534
symbolGraphTransformer: ((inout SymbolGraph) -> ())? = nil
3635
) {
3736
self.bundle = bundle
38-
self.dataLoader = dataLoader
37+
self.dataProvider = dataProvider
3938
self.symbolGraphTransformer = symbolGraphTransformer
4039
}
4140

@@ -61,13 +60,13 @@ struct SymbolGraphLoader {
6160
var loadedGraphs = [URL: (usesExtensionSymbolFormat: Bool?, graph: SymbolKit.SymbolGraph)]()
6261
var loadError: (any Error)?
6362

64-
let loadGraphAtURL: (URL) -> Void = { [dataLoader, bundle] symbolGraphURL in
63+
let loadGraphAtURL: (URL) -> Void = { [dataProvider] symbolGraphURL in
6564
// Bail out in case a symbol graph has already errored
6665
guard loadingLock.sync({ loadError == nil }) else { return }
6766

6867
do {
6968
// Load and decode a single symbol graph file
70-
let data = try dataLoader(symbolGraphURL, bundle)
69+
let data = try dataProvider.contents(of: symbolGraphURL)
7170

7271
var symbolGraph: SymbolGraph
7372

Tests/SwiftDocCTests/Infrastructure/SymbolDisambiguationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class SymbolDisambiguationTests: XCTestCase {
191191
func testMixedLanguageFramework() async throws {
192192
let (bundle, context) = try await testBundleAndContext(named: "MixedLanguageFramework")
193193

194-
var loader = SymbolGraphLoader(bundle: bundle, dataLoader: { url, _ in try context.dataProvider.contents(of: url) })
194+
var loader = SymbolGraphLoader(bundle: bundle, dataProvider: context.dataProvider)
195195
try loader.loadAll()
196196

197197
let references = context.linkResolver.localResolver.referencesForSymbols(in: loader.unifiedGraphs, bundle: bundle, context: context).mapValues(\.path)

Tests/SwiftDocCTests/Infrastructure/SymbolGraph/SymbolGraphLoaderTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,9 +1801,7 @@ class SymbolGraphLoaderTests: XCTestCase {
18011801

18021802
return SymbolGraphLoader(
18031803
bundle: bundle,
1804-
dataLoader: { url, _ in
1805-
try FileManager.default.contents(of: url)
1806-
},
1804+
dataProvider: FileManager.default,
18071805
symbolGraphTransformer: configureSymbolGraph
18081806
)
18091807
}

0 commit comments

Comments
 (0)