diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-06-05 07:31:44 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-05 07:31:44 +1000 |
commit | e8be116ab6d06bed764ad9b6cb253d8de36ae73d (patch) | |
tree | 47f0ac3695ce7dd76fc9af1d7991c7ba685adf85 /cli/bench | |
parent | 1abff0e333861211b5186527bc1c1371709ce3e4 (diff) |
fix(lsp): refactor, fix issues and add benchmark for code lens (#10841)
Diffstat (limited to 'cli/bench')
-rw-r--r-- | cli/bench/fixtures/code_lens.ts | 56 | ||||
-rw-r--r-- | cli/bench/lsp.rs | 75 |
2 files changed, 131 insertions, 0 deletions
diff --git a/cli/bench/fixtures/code_lens.ts b/cli/bench/fixtures/code_lens.ts new file mode 100644 index 000000000..0822e31c4 --- /dev/null +++ b/cli/bench/fixtures/code_lens.ts @@ -0,0 +1,56 @@ +interface A { + a: string; +} + +interface B { + b: string; +} + +interface C { + c: string; +} + +interface D { + d: string; +} + +interface E { + e: string; +} + +interface F { + f: string; +} + +interface G { + g: string; +} + +interface H { + h: string; +} + +class AB implements A, B { + a = "a"; + b = "b"; +} + +class CD implements C, D { + c = "c"; + d = "d"; +} + +class EF implements E, F { + e = "e"; + f = "f"; +} + +class GH implements G, H { + g = "g"; + h = "h"; +} + +new AB().a; +new CD().c; +new EF().e; +new GH().g; 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) |