diff --git a/Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift b/Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift index acb77613f9..5dfdefe6e2 100644 --- a/Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift +++ b/Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift @@ -189,7 +189,6 @@ public class NavigatorIndex { navigatorTree = try NavigatorTree.read( from: url.appendingPathComponent("navigator.index", isDirectory: false), bundleIdentifier: bundleIdentifier, - interfaceLanguages: availabilityIndex.interfaceLanguages, presentationIdentifier: presentationIdentifier, onNodeRead: onNodeRead) } else { @@ -394,7 +393,7 @@ public class NavigatorIndex { */ public func readNavigatorTree(timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, broadcast: NavigatorTree.BroadcastCallback?) throws { let indexURL = url.appendingPathComponent("navigator.index") - try navigatorTree.read(from: indexURL, bundleIdentifier: bundleIdentifier, interfaceLanguages: availabilityIndex.interfaceLanguages, timeout: timeout, delay: delay, queue: queue, broadcast: broadcast) + try navigatorTree.read(from: indexURL, bundleIdentifier: bundleIdentifier, timeout: timeout, delay: delay, queue: queue, broadcast: broadcast) } // MARK: - Data Query diff --git a/Sources/SwiftDocC/Indexing/Navigator/NavigatorTree.swift b/Sources/SwiftDocC/Indexing/Navigator/NavigatorTree.swift index 95a5bd7a12..95d71a53c4 100644 --- a/Sources/SwiftDocC/Indexing/Navigator/NavigatorTree.swift +++ b/Sources/SwiftDocC/Indexing/Navigator/NavigatorTree.swift @@ -99,9 +99,6 @@ public class NavigatorTree { /// The broadcast callback notifies a listener about the latest items loaded from the disk. public typealias BroadcastCallback = (_ items: [NavigatorTree.Node], _ isCompleted: Bool, _ error: Error?) -> Void - // A reference to the reading cursor. - internal var readingCursor: ReadingCursor? = nil - /** Read a tree from disk from a given path. The read is atomically performed, which means it reads all the content of the file from the disk and process the tree from loaded data. @@ -109,7 +106,6 @@ public class NavigatorTree { - Parameters: - url: The file URL from which the tree should be read. - bundleIdentifier: The bundle identifier used to generate the mapping topicID to node on tree. - - interfaceLanguages: A set containing the indication about the interface languages a tree contains. - timeout: The amount of time we can load a batch of items from data, once the timeout time pass, the reading process will reschedule asynchronously using the given queue. - delay: The delay to wait before schedule the next read. Default: 0.01 seconds. @@ -117,10 +113,9 @@ public class NavigatorTree { - presentationIdentifier: Defines if nodes should have a presentation identifier useful in presentation contexts. - broadcast: The callback to update get updates of the current process. */ - public func read(from url: URL, bundleIdentifier: String? = nil, interfaceLanguages: Set, timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, presentationIdentifier: String? = nil, broadcast: BroadcastCallback?) throws { + public func read(from url: URL, bundleIdentifier: String? = nil, timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, presentationIdentifier: String? = nil, broadcast: BroadcastCallback?) throws { let data = try Data(contentsOf: url) let readingCursor = ReadingCursor(data: data) - self.readingCursor = readingCursor func __read() { let deadline = DispatchTime.now() + timeout @@ -141,7 +136,6 @@ public class NavigatorTree { guard let item = NavigatorItem(rawValue: objectData) else { broadcast?(processedNodes, false, Error.invalidData) - self.readingCursor = nil break } @@ -171,7 +165,6 @@ public class NavigatorTree { queue.async(flags: .barrier) { broadcast?(processedNodes, true, nil) } - self.readingCursor = nil } } @@ -183,6 +176,11 @@ public class NavigatorTree { self.root = root } + + @available(*, deprecated, renamed: "read(from:bundleIdentifier:timeout:delay:queue:presentationIdentifier:broadcast:)", message: "Use 'read(from:bundleIdentifier:timeout:delay:queue:presentationIdentifier:broadcast:)' instead. This deprecated API will be removed after 6.1 is released") + public func read(from url: URL, bundleIdentifier: String? = nil, interfaceLanguages: Set, timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, presentationIdentifier: String? = nil, broadcast: BroadcastCallback?) throws { + try self.read(from: url, bundleIdentifier: bundleIdentifier, timeout: timeout, delay: delay, queue: queue, presentationIdentifier: presentationIdentifier, broadcast: broadcast) + } /** Serialize the node and descendants to the disk. @@ -261,7 +259,6 @@ public class NavigatorTree { - Parameters: - url: The file URL from which the tree should be read. - bundleIdentifier: The bundle identifier used to generate the mapping topicID to node on tree. - - interfaceLanguages: A set containing the indication about the interface languages a tree contains. - atomically: Defines if the read should be atomic. - presentationIdentifier: Defines if nodes should have a presentation identifier useful in presentation contexts. - onNodeRead: An action to perform after reading a node. This allows clients to perform arbitrary actions on the node while it is being read from disk. This is useful for clients wanting to attach data to ``NavigatorTree/Node/attributes``. @@ -269,25 +266,21 @@ public class NavigatorTree { static func read( from url: URL, bundleIdentifier: String? = nil, - interfaceLanguages: Set, atomically: Bool = true, presentationIdentifier: String? = nil, onNodeRead: ((NavigatorTree.Node) -> Void)? = nil ) throws -> NavigatorTree { - let interfaceLanguageMap = Dictionary(uniqueKeysWithValues: interfaceLanguages.map{ ($0.mask, $0)}) let path = url.path if atomically { return try readAtomically( from: path, bundleIdentifier: bundleIdentifier, - interfaceLanguageMap: interfaceLanguageMap, presentationIdentifier: presentationIdentifier, onNodeRead: onNodeRead) } return try read( from: path, bundleIdentifier: bundleIdentifier, - interfaceLanguageMap: interfaceLanguageMap, presentationIdentifier: presentationIdentifier, onNodeRead: onNodeRead) } @@ -296,7 +289,6 @@ public class NavigatorTree { fileprivate static func readAtomically( from path: String, bundleIdentifier: String? = nil, - interfaceLanguageMap: [InterfaceLanguage.ID: InterfaceLanguage], presentationIdentifier: String? = nil, onNodeRead: ((NavigatorTree.Node) -> Void)? = nil ) throws -> NavigatorTree { @@ -347,7 +339,6 @@ public class NavigatorTree { fileprivate static func read( from path: String, bundleIdentifier: String? = nil, - interfaceLanguageMap: [InterfaceLanguage.ID: InterfaceLanguage], presentationIdentifier: String? = nil, onNodeRead: ((NavigatorTree.Node) -> Void)? = nil ) throws -> NavigatorTree { diff --git a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift index 9ba69a0956..01193117a5 100644 --- a/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift +++ b/Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift @@ -174,7 +174,7 @@ Root let original = NavigatorTree(root: root) try original.write(to: indexURL) - let readTree = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, interfaceLanguages: [.swift], atomically: true) + let readTree = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, atomically: true) XCTAssertEqual(original.root.countItems(), readTree.root.countItems()) XCTAssertTrue(compare(lhs: original.root, rhs: readTree.root)) @@ -195,7 +195,7 @@ Root XCTAssertTrue(validateTree(node: readTree.root, validator: bundleIdentifierValidator), "The tree has bundle identifier missing.") XCTAssertTrue(validateTree(node: readTree.root, validator: emptyPresentationIdentifierValidator), "The tree has a presentation identifier set which should not be present.") - let treeWithPresentationIdentifier = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, interfaceLanguages: [.swift], atomically: true, presentationIdentifier: "com.example.test") + let treeWithPresentationIdentifier = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, atomically: true, presentationIdentifier: "com.example.test") let presentationIdentifierValidator: (NavigatorTree.Node) -> Bool = { node in return node.presentationIdentifier == "com.example.test" @@ -213,7 +213,6 @@ Root let treeWithAttributes = try NavigatorTree.read( from: indexURL, bundleIdentifier: testBundleIdentifier, - interfaceLanguages: [.swift], atomically: true, presentationIdentifier: "com.example.test", onNodeRead: addAttributes @@ -232,7 +231,6 @@ Root let treeWithAttributesNonAtomic = try NavigatorTree.read( from: indexURL, bundleIdentifier: testBundleIdentifier, - interfaceLanguages: [.swift], atomically: false, presentationIdentifier: "com.example.test", onNodeRead: addAttributes @@ -257,7 +255,6 @@ Root _ = try NavigatorTree.read( from: indexURL, bundleIdentifier: uniqueTestBundleIdentifier, - interfaceLanguages: [.swift], atomically: true ) @@ -275,7 +272,7 @@ Root try original.write(to: indexURL) measure { - _ = try! NavigatorTree.read(from: indexURL, interfaceLanguages: [.swift], atomically: true) + _ = try! NavigatorTree.read(from: indexURL, atomically: true) } #endif } @@ -297,7 +294,7 @@ Root let expectation = XCTestExpectation(description: "Load the tree asynchronously.") let readTree = NavigatorTree() - try! readTree.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in + try! readTree.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in counter += 1 XCTAssertNil(error) if completed { expectation.fulfill() } @@ -310,7 +307,7 @@ Root let expectation2 = XCTestExpectation(description: "Load the tree asynchronously, again with presentation identifier.") let readTreePresentationIdentifier = NavigatorTree() - try! readTreePresentationIdentifier.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main, presentationIdentifier: "com.example.test") { (nodes, completed, error) in + try! readTreePresentationIdentifier.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main, presentationIdentifier: "com.example.test") { (nodes, completed, error) in XCTAssertNil(error) if completed { expectation2.fulfill() } } @@ -336,7 +333,7 @@ Root let indexURL = targetURL.appendingPathComponent("nav.index") let readTree = NavigatorTree() - XCTAssertThrowsError(try readTree.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main, broadcast: nil)) + XCTAssertThrowsError(try readTree.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main, broadcast: nil)) try XCTAssertEqual( RenderIndex.fromURL(targetURL.appendingPathComponent("index.json")), @@ -371,7 +368,7 @@ Root let expectation = XCTestExpectation(description: "Load the tree asynchronously.") let readTree = NavigatorTree() - try! readTree.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in + try! readTree.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in counter += 1 XCTAssertNil(error) if completed { expectation.fulfill() }