Skip to content

Commit

Permalink
rework and fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed May 6, 2021
1 parent 4f86ac6 commit 9a61a80
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 88 deletions.
4 changes: 4 additions & 0 deletions cli/bench/fixtures/initialize_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"willSaveWaitUntil": true,
"didSave": true
}
},
"workspace": {
"configuration": true,
"workspaceFolders": true
}
}
}
48 changes: 48 additions & 0 deletions cli/bench/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -324,6 +362,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");

Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Settings {
pub struct Config {
pub client_capabilities: ClientCapabilities,
pub root_uri: Option<Url>,
specifier_settings: HashMap<ModuleSpecifier, Settings>,
pub specifier_settings: HashMap<ModuleSpecifier, Settings>,
pub workspace_settings: Settings,
}

Expand Down
Loading

0 comments on commit 9a61a80

Please sign in to comment.