summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-10-21 22:16:39 +0100
committerGitHub <noreply@github.com>2024-10-21 22:16:39 +0100
commit9e25a4ebbfa848e58415f267d5991bead7de4808 (patch)
tree5b3017f58fb83925755ebc344711040457f6a30f /tests/integration
parent49d9c02bfa964082fc51df32dfb7ed3e05457508 (diff)
fix(lsp): import-map-remap quickfix for type imports (#26454)
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/lsp_tests.rs111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 0b7c5dd3f..35a412b28 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -6778,6 +6778,117 @@ fn lsp_code_actions_imports_dts() {
}
#[test]
+fn lsp_code_actions_import_map_remap() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "imports": {
+ "foo": "./foo.ts",
+ "bar": "./bar.ts",
+ },
+ })
+ .to_string(),
+ );
+ temp_dir.write("foo.ts", "");
+ temp_dir.write("bar.ts", "");
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ let diagnostics = client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.url().join("file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": r#"
+ import "./foo.ts";
+ import type {} from "./bar.ts";
+ "#,
+ }
+ }));
+ let res = client.write_request(
+ "textDocument/codeAction",
+ json!({
+ "textDocument": { "uri": temp_dir.url().join("file.ts").unwrap() },
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 3, "character": 0 },
+ },
+ "context": {
+ "diagnostics": diagnostics.all(),
+ "only": ["quickfix"],
+ },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([
+ {
+ "title": "Update \"./foo.ts\" to \"foo\" to use import map.",
+ "kind": "quickfix",
+ "diagnostics": [
+ {
+ "range": {
+ "start": { "line": 1, "character": 15 },
+ "end": { "line": 1, "character": 25 },
+ },
+ "severity": 4,
+ "code": "import-map-remap",
+ "source": "deno",
+ "message": "The import specifier can be remapped to \"foo\" which will resolve it via the active import map.",
+ "data": { "from": "./foo.ts", "to": "foo" },
+ },
+ ],
+ "edit": {
+ "changes": {
+ temp_dir.url().join("file.ts").unwrap(): [
+ {
+ "range": {
+ "start": { "line": 1, "character": 15 },
+ "end": { "line": 1, "character": 25 },
+ },
+ "newText": "\"foo\"",
+ },
+ ],
+ },
+ },
+ },
+ {
+ "title": "Update \"./bar.ts\" to \"bar\" to use import map.",
+ "kind": "quickfix",
+ "diagnostics": [
+ {
+ "range": {
+ "start": { "line": 2, "character": 28 },
+ "end": { "line": 2, "character": 38 },
+ },
+ "severity": 4,
+ "code": "import-map-remap",
+ "source": "deno",
+ "message": "The import specifier can be remapped to \"bar\" which will resolve it via the active import map.",
+ "data": { "from": "./bar.ts", "to": "bar" },
+ },
+ ],
+ "edit": {
+ "changes": {
+ temp_dir.url().join("file.ts").unwrap(): [
+ {
+ "range": {
+ "start": { "line": 2, "character": 28 },
+ "end": { "line": 2, "character": 38 },
+ },
+ "newText": "\"bar\"",
+ },
+ ],
+ },
+ },
+ },
+ ]),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_code_actions_refactor() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let mut client = context.new_lsp_command().build();