summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-08-14 22:38:18 +0100
committerGitHub <noreply@github.com>2024-08-14 22:38:18 +0100
commit4eff1e8ec4c12c709ce7e0e6d430ecbbc571bfbe (patch)
tree88c3bae373e03e20ca251b7eb91b5c1fa53d5b20 /tests
parent3a3315cc7f3466ce229f6f150402d5ccf72b3d1d (diff)
fix(lsp): import map lookup for jsr subpath auto import (#25025)
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/lsp_tests.rs74
-rw-r--r--tests/registry/jsr/@std/url/0.220.1/join.ts2
-rw-r--r--tests/registry/jsr/@std/url/0.220.1/normalize.ts2
3 files changed, 76 insertions, 2 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index e1ee25058..3d20efbba 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -5483,6 +5483,80 @@ fn lsp_jsr_auto_import_completion_import_map() {
}
#[test]
+fn lsp_jsr_auto_import_completion_import_map_sub_path() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "imports": {
+ "@std/path": "jsr:@std/path@^0.220.1",
+ },
+ })
+ .to_string(),
+ );
+ let file = source_file(
+ temp_dir.path().join("file.ts"),
+ r#"
+ // Adds jsr:@std/path@^0.220.1/normalize to the module graph.
+ import "jsr:@std/url@^0.220.1/normalize";
+ normalize
+ "#,
+ );
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], file.uri()],
+ }),
+ );
+ client.read_diagnostics();
+ client.did_open_file(&file);
+ let list = client.get_completion_list(
+ file.uri(),
+ (3, 15),
+ json!({ "triggerKind": 1 }),
+ );
+ let item = list
+ .items
+ .iter()
+ .find(|i| {
+ i.label == "normalize"
+ && json!(&i.label_details)
+ .to_string()
+ .contains("\"@std/path/posix/normalize\"")
+ })
+ .unwrap();
+ let res = client.write_request("completionItem/resolve", json!(item));
+ assert_eq!(
+ res,
+ json!({
+ "label": "normalize",
+ "labelDetails": { "description": "@std/path/posix/normalize" },
+ "kind": 3,
+ "detail": "function normalize(path: string): string",
+ "documentation": { "kind": "markdown", "value": "Normalize the `path`, resolving `'..'` and `'.'` segments.\nNote that resolving these segments does not necessarily mean that all will be eliminated.\nA `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.\n\n*@param* - path to be normalized" },
+ "sortText": "\u{ffff}16_0",
+ "additionalTextEdits": [
+ {
+ "range": {
+ "start": { "line": 2, "character": 6 },
+ "end": { "line": 2, "character": 6 },
+ },
+ "newText": "import { normalize } from \"@std/path/posix/normalize\";\n",
+ },
+ ],
+ }),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_jsr_code_action_missing_declaration() {
let context = TestContextBuilder::new()
.use_http_server()
diff --git a/tests/registry/jsr/@std/url/0.220.1/join.ts b/tests/registry/jsr/@std/url/0.220.1/join.ts
index 158994ad3..b9c8f19d3 100644
--- a/tests/registry/jsr/@std/url/0.220.1/join.ts
+++ b/tests/registry/jsr/@std/url/0.220.1/join.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
-import { join as posixJoin } from "jsr:/@std/path@^0.220.1/posix/join";
+import { join as posixJoin } from "jsr:@std/path@^0.220.1/posix/join";
/**
* Join a base `URL` and a series of `paths`, then normalizes the resulting URL.
diff --git a/tests/registry/jsr/@std/url/0.220.1/normalize.ts b/tests/registry/jsr/@std/url/0.220.1/normalize.ts
index dc2305701..e8d728435 100644
--- a/tests/registry/jsr/@std/url/0.220.1/normalize.ts
+++ b/tests/registry/jsr/@std/url/0.220.1/normalize.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
-import { normalize as posixNormalize } from "jsr:/@std/path@^0.220.1/posix/normalize";
+import { normalize as posixNormalize } from "jsr:@std/path@^0.220.1/posix/normalize";
/**
* Normalize the `URL`, resolving `'..'` and `'.'` segments and multiple