Skip to content

Commit

Permalink
refactor(lsp): improve test client initialization (denoland#18015)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 8, 2023
1 parent f2e5e01 commit 25d98ca
Show file tree
Hide file tree
Showing 92 changed files with 3,937 additions and 5,789 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ hyper = "0.14.18"
indexmap = { version = "1.9.2", features = ["serde"] }
libc = "0.2.126"
log = "=0.4.17"
lsp-types = "=0.93.2" # used by tower-lsp and "proposed" feature is unstable in patch releases
lzzzz = "1.0"
notify = "=5.0.0"
once_cell = "1.17.1"
Expand Down Expand Up @@ -122,6 +123,7 @@ tokio = { version = "=1.25.0", features = ["full"] }
tokio-rustls = "0.23.3"
tokio-tungstenite = "0.16.1"
tokio-util = "0.7.4"
tower-lsp = { version = "=0.17.0", features = ["proposed"] }
url = { version = "2.3.1", features = ["serde", "expose_internals"] }
uuid = { version = "1.3.0", features = ["v4"] }
zstd = "=0.11.2"
Expand Down
4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ indexmap.workspace = true
jsonc-parser = { version = "=0.21.0", features = ["serde"] }
libc.workspace = true
log = { workspace = true, features = ["serde"] }
lsp-types = "=0.93.2" # used by tower-lsp and "proposed" feature is unstable in patch releases
lsp-types.workspace = true
lzzzz = '1.0'
mitata = "=0.0.7"
monch = "=0.4.1"
Expand All @@ -104,7 +104,7 @@ text_lines = "=0.6.0"
thiserror = "=1.0.38"
tokio.workspace = true
tokio-util.workspace = true
tower-lsp = { version = "=0.17.0", features = ["proposed"] }
tower-lsp.workspace = true
twox-hash = "=1.6.3"
typed-arena = "=2.0.1"
uuid = { workspace = true, features = ["serde"] }
Expand Down
42 changes: 9 additions & 33 deletions cli/bench/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ use deno_core::url::Url;
use std::collections::HashMap;
use std::path::Path;
use std::time::Duration;
use test_util::lsp::LspClient;
use test_util::lsp::LspClientBuilder;
use test_util::lsp::LspResponseError;
use tower_lsp::lsp_types as lsp;

static FIXTURE_CODE_LENS_TS: &str = include_str!("testdata/code_lens.ts");
static FIXTURE_DB_TS: &str = include_str!("testdata/db.ts");
static FIXTURE_DB_MESSAGES: &[u8] = include_bytes!("testdata/db_messages.json");
static FIXTURE_INIT_JSON: &[u8] =
include_bytes!("testdata/initialize_params.json");

#[derive(Debug, Deserialize)]
enum FixtureType {
Expand All @@ -44,14 +42,8 @@ struct FixtureMessage {
/// the end of the document and does a level of hovering and gets quick fix
/// code actions.
fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;

let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
let (_, response_error): (Option<Value>, Option<LspResponseError>) =
client.write_request("initialize", params)?;
assert!(response_error.is_none());

client.write_notification("initialized", json!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();

client.write_notification(
"textDocument/didOpen",
Expand Down Expand Up @@ -125,13 +117,8 @@ fn bench_big_file_edits(deno_exe: &Path) -> Result<Duration, AnyError> {
}

fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;

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!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();

client.write_notification(
"textDocument/didOpen",
Expand Down Expand Up @@ -189,13 +176,8 @@ fn bench_code_lens(deno_exe: &Path) -> Result<Duration, AnyError> {
}

fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;

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!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();

for i in 0..10 {
client.write_notification(
Expand Down Expand Up @@ -285,14 +267,8 @@ fn bench_find_replace(deno_exe: &Path) -> Result<Duration, AnyError> {

/// A test that starts up the LSP, opens a single line document, and exits.
fn bench_startup_shutdown(deno_exe: &Path) -> Result<Duration, AnyError> {
let mut client = LspClient::new(deno_exe, false)?;

let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON)?;
let (_, response_error) =
client.write_request::<_, _, Value>("initialize", params)?;
assert!(response_error.is_none());

client.write_notification("initialized", json!({}))?;
let mut client = LspClientBuilder::new().deno_exe(deno_exe).build();
client.initialize_default();

client.write_notification(
"textDocument/didOpen",
Expand Down
15 changes: 3 additions & 12 deletions cli/bench/lsp_bench_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@
use deno_bench_util::bencher::benchmark_group;
use deno_bench_util::bencher::benchmark_main;
use deno_bench_util::bencher::Bencher;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use test_util::lsp::LspClient;
use test_util::lsp::LspClientBuilder;

// Intended to match the benchmark in quick-lint-js
// https://github.com/quick-lint/quick-lint-js/blob/35207e6616267c6c81be63f47ce97ec2452d60df/benchmark/benchmark-lsp/lsp-benchmarks.cpp#L223-L268
fn incremental_change_wait(bench: &mut Bencher) {
let deno_exe = test_util::deno_exe_path();
let mut client = LspClient::new(&deno_exe, false).unwrap();

static FIXTURE_INIT_JSON: &[u8] =
include_bytes!("testdata/initialize_params.json");
let params: Value = serde_json::from_slice(FIXTURE_INIT_JSON).unwrap();
let (_, maybe_err) = client
.write_request::<_, _, Value>("initialize", params)
.unwrap();
assert!(maybe_err.is_none());
client.write_notification("initialized", json!({})).unwrap();
let mut client = LspClientBuilder::new().build();
client.initialize_default();

client
.write_notification(
Expand Down
Loading

0 comments on commit 25d98ca

Please sign in to comment.