mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
fix(lsp): resolve remote import maps (#20651)
This commit is contained in:
parent
33f84321b2
commit
98ef7bd818
5 changed files with 54 additions and 6 deletions
|
@ -1052,13 +1052,8 @@ impl Inner {
|
|||
lsp_log!("Warning: Import map \"{}\" configured in \"{}\" being ignored due to an import map being explicitly configured in workspace settings.", import_map_path, config_file.specifier);
|
||||
}
|
||||
}
|
||||
if let Ok(url) = Url::from_file_path(&import_map_str) {
|
||||
if let Ok(url) = Url::parse(&import_map_str) {
|
||||
Some(url)
|
||||
} else if import_map_str.starts_with("data:") {
|
||||
let import_map_url = Url::parse(&import_map_str).map_err(|_| {
|
||||
anyhow!("Bad data url for import map: {}", import_map_str)
|
||||
})?;
|
||||
Some(import_map_url)
|
||||
} else if let Some(root_uri) = self.config.root_uri() {
|
||||
let root_path = specifier_to_file_path(root_uri)?;
|
||||
let import_map_path = root_path.join(&import_map_str);
|
||||
|
|
|
@ -206,6 +206,54 @@ fn lsp_import_map() {
|
|||
client.shutdown();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lsp_import_map_remote() {
|
||||
let context = TestContextBuilder::new()
|
||||
.use_http_server()
|
||||
.use_temp_cwd()
|
||||
.build();
|
||||
let temp_dir = context.temp_dir();
|
||||
temp_dir.write(
|
||||
"deno.json",
|
||||
json!({
|
||||
"importMap": "http://localhost:4545/import_maps/import_map.json",
|
||||
})
|
||||
.to_string(),
|
||||
);
|
||||
temp_dir.write(
|
||||
"file.ts",
|
||||
r#"
|
||||
import { printHello } from "print_hello";
|
||||
printHello();
|
||||
"#,
|
||||
);
|
||||
let mut client = context.new_lsp_command().build();
|
||||
client.initialize(|builder| {
|
||||
builder.set_import_map("http://localhost:4545/import_maps/import_map.json");
|
||||
});
|
||||
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_data_url() {
|
||||
let context = TestContextBuilder::new().use_temp_cwd().build();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"imports": {
|
||||
"print_hello": "./print_hello.ts",
|
||||
"moment": "./moment/moment.ts",
|
||||
"moment/": "./moment/",
|
||||
"lodash": "./lodash/lodash.ts",
|
||||
|
|
3
cli/tests/testdata/import_maps/print_hello.ts
vendored
Normal file
3
cli/tests/testdata/import_maps/print_hello.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function printHello() {
|
||||
console.log("Hello, world!");
|
||||
}
|
|
@ -220,6 +220,7 @@ impl InitializeParamsBuilder {
|
|||
}),
|
||||
root_uri: None,
|
||||
initialization_options: Some(json!({
|
||||
"enableBuiltinCommands": true,
|
||||
"enable": true,
|
||||
"cache": null,
|
||||
"certificateStores": null,
|
||||
|
|
Loading…
Reference in a new issue