diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 4c7a966374..1c0a134d9e 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 3ae7381117..cbf2725810 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/" } @@ -654,6 +655,51 @@ fn lsp_import_map_config_file_auto_discovered_symlink() { client.shutdown(); } +#[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();