From 0087402094b9622e48787572ffa30a41f6b7f3ab Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 9 Jul 2024 14:25:50 +0100 Subject: [PATCH] fix(lsp): do sloppy resolution for node-to-node imports in byonm (#24481) --- cli/resolver.rs | 4 +++- tests/integration/lsp_tests.rs | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/cli/resolver.rs b/cli/resolver.rs index 26cf16ba9579a7..d1e5d91e7ec37e 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -682,7 +682,9 @@ impl Resolver for CliGraphResolver { } } } - } else if referrer.scheme() == "file" { + } + + if referrer.scheme() == "file" { if let Some(node_resolver) = &self.node_resolver { let node_result = node_resolver.resolve_if_in_npm_package( specifier, diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 2111c6f076bb47..d42bff4bd11aac 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -14275,6 +14275,46 @@ fn sloppy_imports_not_enabled() { client.shutdown(); } +// Regression test for https://github.com/denoland/deno/issues/24457. +#[test] +fn lsp_byonm_js_import_resolves_to_dts() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .add_npm_env_vars() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "deno.json", + json!({ + "unstable": ["byonm"], + }) + .to_string(), + ); + temp_dir.write( + "package.json", + json!({ + "dependencies": { + "postcss": "*", + }, + }) + .to_string(), + ); + context.run_npm("install"); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + let diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("node_modules/postcss/lib/comment.d.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": temp_dir.path().join("node_modules/postcss/lib/comment.d.ts").read_to_string(), + } + })); + assert_eq!(json!(diagnostics.all()), json!([])); + client.shutdown(); +} + #[test] fn decorators_tc39() { let context = TestContextBuilder::new().use_temp_cwd().build();