mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-06 18:24:36 +01:00
[test] Add listenToUnitEvents to initialization options
This should be used along with polling to explicitly control when index data is read in tests that are outside the sourcekit-lsp process.
This commit is contained in:
@@ -222,18 +222,28 @@ extension SourceKitServer {
|
||||
// MARK: - General
|
||||
|
||||
func initialize(_ req: Request<InitializeRequest>) {
|
||||
|
||||
var indexOptions = IndexOptions()
|
||||
if case .dictionary(let options) = req.params.initializationOptions {
|
||||
if case .bool(let listenToUnitEvents) = options["listenToUnitEvents"] {
|
||||
indexOptions.listenToUnitEvents = listenToUnitEvents
|
||||
}
|
||||
}
|
||||
|
||||
if let url = req.params.rootURL {
|
||||
self.workspace = try? Workspace(
|
||||
url: url,
|
||||
clientCapabilities: req.params.capabilities,
|
||||
toolchainRegistry: self.toolchainRegistry,
|
||||
buildSetup: self.buildSetup)
|
||||
buildSetup: self.buildSetup,
|
||||
indexOptions: indexOptions)
|
||||
} else if let path = req.params.rootPath {
|
||||
self.workspace = try? Workspace(
|
||||
url: URL(fileURLWithPath: path),
|
||||
clientCapabilities: req.params.capabilities,
|
||||
toolchainRegistry: self.toolchainRegistry,
|
||||
buildSetup: self.buildSetup)
|
||||
buildSetup: self.buildSetup,
|
||||
indexOptions: indexOptions)
|
||||
}
|
||||
|
||||
if self.workspace == nil {
|
||||
|
||||
@@ -71,7 +71,8 @@ public final class Workspace {
|
||||
url: URL,
|
||||
clientCapabilities: ClientCapabilities,
|
||||
toolchainRegistry: ToolchainRegistry,
|
||||
buildSetup: BuildSetup
|
||||
buildSetup: BuildSetup,
|
||||
indexOptions: IndexOptions = IndexOptions()
|
||||
) throws {
|
||||
|
||||
self.buildSetup = buildSetup
|
||||
@@ -99,7 +100,8 @@ public final class Workspace {
|
||||
self.index = try IndexStoreDB(
|
||||
storePath: storePath.pathString,
|
||||
databasePath: dbPath.pathString,
|
||||
library: lib)
|
||||
library: lib,
|
||||
listenToUnitEvents: indexOptions.listenToUnitEvents)
|
||||
log("opened IndexStoreDB at \(dbPath) with store path \(storePath)")
|
||||
} catch {
|
||||
log("failed to open IndexStoreDB: \(error.localizedDescription)", level: .error)
|
||||
@@ -107,3 +109,14 @@ public final class Workspace {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct IndexOptions {
|
||||
|
||||
/// *For Testing* Whether the index should listen to unit events, or wait for
|
||||
/// explicit calls to pollForUnitChangesAndWait().
|
||||
public var listenToUnitEvents: Bool
|
||||
|
||||
public init(listenToUnitEvents: Bool = false) {
|
||||
self.listenToUnitEvents = listenToUnitEvents
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user