summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-03-01 21:13:04 -0500
committerGitHub <noreply@github.com>2024-03-01 21:13:04 -0500
commit0973e8e8594cb01631306474cd4032245ef956cf (patch)
treee7df397af77c1ed4e3ba84924785630b3fd8e0bc
parent15f5f74eb745915e68b3bc16b9ec048b94e26b97 (diff)
fix(lsp): regression - caching in lsp broken when config with imports has comments (#22666)
Caused by https://github.com/denoland/deno/pull/22553 Closes #22664
-rw-r--r--cli/lsp/language_server.rs10
-rw-r--r--tests/integration/lsp_tests.rs46
2 files changed, 52 insertions, 4 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 4c7a96637..1c0a134d9 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -974,7 +974,7 @@ impl Inner {
return Ok(None);
};
lsp_log!(
- "Setting import map from workspace settings: \"{}\"",
+ "Using import map from workspace settings: \"{}\"",
import_map_str
);
if let Some(config_file) = self.config.maybe_config_file() {
@@ -3685,9 +3685,11 @@ impl Inner {
self.maybe_package_json.clone(),
force_global_cache,
)?;
- cli_options.set_import_map_specifier(
- self.maybe_import_map.as_ref().map(|m| m.base_url().clone()),
- );
+ // don't use the specifier in self.maybe_import_map because it's not
+ // necessarily an import map specifier (could be a deno.json)
+ if let Some(import_map) = self.resolve_import_map_specifier()? {
+ cli_options.set_import_map_specifier(Some(import_map));
+ }
let open_docs = self.documents.documents(DocumentsFilter::OpenDiagnosable);
Ok(Some(PrepareCacheResult {
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 3ae738111..cbf272581 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -349,6 +349,7 @@ fn lsp_import_map_embedded_in_config_file() {
temp_dir.write(
"deno.embedded_import_map.jsonc",
r#"{
+ // some comment
"imports": {
"/~/": "./lib/"
}
@@ -655,6 +656,51 @@ fn lsp_import_map_config_file_auto_discovered_symlink() {
}
#[test]
+fn lsp_deno_json_imports_comments_cache() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.jsonc",
+ r#"{
+ // comment
+ "imports": {
+ "print_hello": "http://localhost:4545/import_maps/print_hello.ts",
+ },
+ }"#,
+ );
+ temp_dir.write(
+ "file.ts",
+ r#"
+ import { printHello } from "print_hello";
+ printHello();
+ "#,
+ );
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("file.ts").unwrap()],
+ }),
+ );
+
+ let diagnostics = client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": temp_dir.read_to_string("file.ts"),
+ }
+ }));
+ assert_eq!(diagnostics.all(), vec![]);
+ client.shutdown();
+}
+
+#[test]
fn lsp_import_map_node_specifiers() {
let context = TestContextBuilder::for_npm().use_temp_cwd().build();
let temp_dir = context.temp_dir();