1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

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
This commit is contained in:
David Sherret 2024-03-01 21:13:04 -05:00 committed by GitHub
parent 15f5f74eb7
commit 0973e8e859
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 4 deletions

View file

@ -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 {

View file

@ -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();