summaryrefslogtreecommitdiff
path: root/cli/bench/lsp.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2021-06-05 07:31:44 +1000
committerGitHub <noreply@github.com>2021-06-05 07:31:44 +1000
commite8be116ab6d06bed764ad9b6cb253d8de36ae73d (patch)
tree47f0ac3695ce7dd76fc9af1d7991c7ba685adf85 /cli/bench/lsp.rs
parent1abff0e333861211b5186527bc1c1371709ce3e4 (diff)
fix(lsp): refactor, fix issues and add benchmark for code lens (#10841)
Diffstat (limited to 'cli/bench/lsp.rs')
-rw-r--r--cli/bench/lsp.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/cli/bench/lsp.rs b/cli/bench/lsp.rs
index a227e5a99..3ec914d9e 100644
--- a/cli/bench/lsp.rs
+++ b/cli/bench/lsp.rs
@@ -13,6 +13,7 @@ use std::time::Duration;
use test_util::lsp::LspClient;
use test_util::lsp::LspResponseError;
+static FIXTURE_CODE_LENS_TS: &str = include_str!("fixtures/code_lens.ts");
static FIXTURE_DB_TS: &str = include_str!("fixtures/db.ts");
static FIXTURE_DB_MESSAGES: &[u8] = include_bytes!("fixtures/db_messages.json");
static FIXTURE_INIT_JSON: &[u8] =
@@ -123,6 +124,70 @@ fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
Ok(client.duration())
}
+fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
+ let mut client = LspClient::new(deno_exe)?;
+
+ let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
+ let (_, maybe_err) =
+ client.write_request::<_, _, Value>("initialize", params)?;
+ assert!(maybe_err.is_none());
+ client.write_notification("initialized", json!({}))?;
+
+ client.write_notification(
+ "textDocument/didOpen",
+ json!({
+ "textDocument": {
+ "uri": "file:///fixtures/code_lens.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": FIXTURE_CODE_LENS_TS
+ }
+ }),
+ )?;
+
+ 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()?;
+ assert_eq!(method, "textDocument/publishDiagnostics");
+ let (method, _): (String, Option<Value>) = client.read_notification()?;
+ assert_eq!(method, "textDocument/publishDiagnostics");
+
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, Vec<lsp::CodeLens>>(
+ "textDocument/codeLens",
+ json!({
+ "textDocument": {
+ "uri": "file:///fixtures/code_lens.ts"
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert!(maybe_res.is_some());
+ let res = maybe_res.unwrap();
+ assert!(!res.is_empty());
+
+ for code_lens in res {
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, lsp::CodeLens>("codeLens/resolve", code_lens)
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert!(maybe_res.is_some());
+ }
+
+ Ok(client.duration())
+}
+
fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe)?;
@@ -304,6 +369,16 @@ pub(crate) fn benchmarks(
println!(" ({} runs, mean: {}ms)", times.len(), mean);
exec_times.insert("find_replace".to_string(), mean);
+ println!(" - Code Lens");
+ let mut times = Vec::new();
+ for _ in 0..10 {
+ times.push(bench_code_lens(deno_exe)?);
+ }
+ let mean =
+ (times.iter().sum::<Duration>() / times.len() as u32).as_millis() as u64;
+ println!(" ({} runs, mean: {}ms)", times.len(), mean);
+ exec_times.insert("code_lens".to_string(), mean);
+
println!("<- End benchmarking lsp");
Ok(exec_times)