diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-02-21 02:45:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 02:45:00 +0000 |
commit | e32c704970d9c332367757cbd21f1905c2d11486 (patch) | |
tree | 410c36122a4b0cba64721db52734e7ba94569cff /tests/integration/lsp_tests.rs | |
parent | 77b90f408c4244e8ee2e4b3bd26c441d4a250671 (diff) |
feat(lsp): auto-import completions for jsr specifiers (#22462)
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r-- | tests/integration/lsp_tests.rs | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 34ea7362c..3ae738111 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -4832,6 +4832,154 @@ fn lsp_jsr_lockfile() { } #[test] +fn lsp_jsr_auto_import_completion() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "main.ts", + r#" + import "jsr:@denotest/add@1"; + "#, + ); + 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("main.ts").unwrap(), + ], + }), + ); + client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": r#"add"#, + } + })); + let list = client.get_completion_list( + temp_dir.uri().join("file.ts").unwrap(), + (0, 3), + json!({ "triggerKind": 1 }), + ); + assert!(!list.is_incomplete); + assert_eq!(list.items.len(), 261); + let item = list.items.iter().find(|i| i.label == "add").unwrap(); + assert_eq!(&item.label, "add"); + assert_eq!( + json!(&item.label_details), + json!({ "description": "jsr:@denotest/add@1" }) + ); + + let res = client.write_request("completionItem/resolve", json!(item)); + assert_eq!( + res, + json!({ + "label": "add", + "labelDetails": { "description": "jsr:@denotest/add@1" }, + "kind": 3, + "detail": "function add(a: number, b: number): number", + "documentation": { "kind": "markdown", "value": "" }, + "sortText": "\u{ffff}16_1", + "additionalTextEdits": [ + { + "range": { + "start": { "line": 0, "character": 0 }, + "end": { "line": 0, "character": 0 }, + }, + "newText": "import { add } from \"jsr:@denotest/add@1\";\n\n", + }, + ], + }) + ); + client.shutdown(); +} + +#[test] +fn lsp_jsr_auto_import_completion_import_map() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "deno.json", + json!({ + "imports": { + "add": "jsr:@denotest/add@^1.0", + }, + }) + .to_string(), + ); + temp_dir.write( + "main.ts", + r#" + import "jsr:@denotest/add@1"; + "#, + ); + 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("main.ts").unwrap(), + ], + }), + ); + client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": r#"add"#, + } + })); + let list = client.get_completion_list( + temp_dir.uri().join("file.ts").unwrap(), + (0, 3), + json!({ "triggerKind": 1 }), + ); + assert!(!list.is_incomplete); + assert_eq!(list.items.len(), 261); + let item = list.items.iter().find(|i| i.label == "add").unwrap(); + assert_eq!(&item.label, "add"); + assert_eq!(json!(&item.label_details), json!({ "description": "add" })); + + let res = client.write_request("completionItem/resolve", json!(item)); + assert_eq!( + res, + json!({ + "label": "add", + "labelDetails": { "description": "add" }, + "kind": 3, + "detail": "function add(a: number, b: number): number", + "documentation": { "kind": "markdown", "value": "" }, + "sortText": "\u{ffff}16_0", + "additionalTextEdits": [ + { + "range": { + "start": { "line": 0, "character": 0 }, + "end": { "line": 0, "character": 0 }, + }, + "newText": "import { add } from \"add\";\n\n", + }, + ], + }) + ); + client.shutdown(); +} + +#[test] fn lsp_code_actions_deno_cache_npm() { let context = TestContextBuilder::new().use_temp_cwd().build(); let mut client = context.new_lsp_command().build(); |