From 83f92474c5e8375ebe2213b4d62d4211fd011c2f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 5 Apr 2024 18:33:01 -0400 Subject: perf(lsp): use lockfile to reduce npm pkg resolution time (#23247) This functionality was broken. The series of events was: 1. Load the npm resolution from the lockfile. 2. Discover only a subset of the specifiers in the documents. 3. Clear the npm snapshot. 4. Redo npm resolution with the new specifiers (~500ms). What this now does: 1. Load the npm resolution from the lockfile. 2. Discover only a subset of the specifiers in the documents and take into account the specifiers from the lockfile. 3. Do not redo resolution (~1ms). --- tests/integration/lsp_tests.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/integration') diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 862de41f6..5ec3117e6 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -12253,3 +12253,40 @@ C.test(); client.shutdown(); } + +#[test] +fn lsp_uses_lockfile_for_npm_initialization() { + let context = TestContextBuilder::for_npm().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + temp_dir.write("deno.json", "{}"); + // use two npm packages here + temp_dir.write("main.ts", "import 'npm:@denotest/esm-basic'; import 'npm:@denotest/cjs-default-export';"); + context + .new_command() + .args("run main.ts") + .run() + .skip_output_check(); + // remove one of the npm packages and let the other one be found via the lockfile + temp_dir.write("main.ts", "import 'npm:@denotest/esm-basic';"); + assert!(temp_dir.path().join("deno.lock").exists()); + let mut client = context + .new_lsp_command() + .capture_stderr() + .log_debug() + .build(); + client.initialize_default(); + let mut skipping_count = 0; + client.wait_until_stderr_line(|line| { + if line.contains("Skipping pending npm resolution.") { + skipping_count += 1; + } + assert!( + !line.contains("Running pending npm resolution."), + "Line: {}", + line + ); + line.contains("Server ready.") + }); + assert_eq!(skipping_count, 1); + client.shutdown(); +} -- cgit v1.2.3