summaryrefslogtreecommitdiff
path: root/cli/bench/lsp.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2021-05-10 11:16:04 +1000
committerGitHub <noreply@github.com>2021-05-10 11:16:04 +1000
commit84733d90c7cf9b6768acf78f4204b2293f2d1bc0 (patch)
tree77b46b8c22a441895205d8898bb27a41c20bdf51 /cli/bench/lsp.rs
parent33b1a6ed617a9e3f9448d6699f6fca8af7330c80 (diff)
feat: support workspace folders configuration (#10488)
Ref #8643
Diffstat (limited to 'cli/bench/lsp.rs')
-rw-r--r--cli/bench/lsp.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs
index aea238441..173c52774 100644
--- a/cli/bench/lsp.rs
+++ b/cli/bench/lsp.rs
@@ -184,6 +184,22 @@ impl LspClient {
}
}
+ fn read_request<R>(&mut self) -> Result<(u64, String, Option<R>), AnyError>
+ where
+ R: de::DeserializeOwned,
+ {
+ loop {
+ if let LspMessage::Request(id, method, maybe_params) = self.read()? {
+ if let Some(p) = maybe_params {
+ let params = serde_json::from_value(p)?;
+ return Ok((id, method, Some(params)));
+ } else {
+ return Ok((id, method, None));
+ }
+ }
+ }
+ }
+
fn write(&mut self, value: Value) -> Result<(), AnyError> {
let value_str = value.to_string();
let msg = format!(
@@ -222,6 +238,18 @@ impl LspClient {
}
}
+ fn write_response<V>(&mut self, id: u64, result: V) -> Result<(), AnyError>
+ where
+ V: Serialize,
+ {
+ let value = json!({
+ "jsonrpc": "2.0",
+ "id": id,
+ "result": result
+ });
+ self.write(value)
+ }
+
fn write_notification<S, V>(
&mut self,
method: S,
@@ -266,6 +294,16 @@ fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
}),
)?;
+ let (id, method, _): (u64, String, Option<Value>) = client.read_request()?;
+ assert_eq!(method, "workspace/configuration");
+
+ client.write_response(
+ id,
+ json!({
+ "enable": true
+ }),
+ )?;
+
let (method, _): (String, Option<Value>) = client.read_notification()?;
assert_eq!(method, "textDocument/publishDiagnostics");
let (method, _): (String, Option<Value>) = client.read_notification()?;
@@ -328,6 +366,16 @@ fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
}),
)?;
+ let (id, method, _): (u64, String, Option<Value>) = client.read_request()?;
+ assert_eq!(method, "workspace/configuration");
+
+ client.write_response(
+ id,
+ json!({
+ "enable": true
+ }),
+ )?;
+
let (method, _): (String, Option<Value>) = client.read_notification()?;
assert_eq!(method, "textDocument/publishDiagnostics");
let (method, _): (String, Option<Value>) = client.read_notification()?;