[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:
Ben Langmuir
2019-08-22 14:53:50 -07:00
parent 9ed80c545e
commit ff7d8c1930
2 changed files with 27 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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
}
}