diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-05-21 21:15:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-21 21:15:16 +0100 |
commit | cc8c0609ebec9f101a1739a0c42c91718ca2abba (patch) | |
tree | 2d62b2b2250a1e478e7d06cd0983a0681acdd6ad /tests/integration/lsp_tests.rs | |
parent | ddb5449f42051a2c7e92142a5d0750cdc49cb281 (diff) |
fix(lsp): apply import fix to missing declaration code action (#23924)
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r-- | tests/integration/lsp_tests.rs | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 347324899..ed95541d2 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -5365,6 +5365,126 @@ fn lsp_jsr_auto_import_completion_import_map() { } #[test] +fn lsp_jsr_code_action_missing_declaration() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + let file = source_file( + temp_dir.path().join("file.ts"), + r#" + import { someFunction } from "jsr:@denotest/types-file"; + assertReturnType(someFunction()); + "#, + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.write_request( + "workspace/executeCommand", + json!({ + "command": "deno.cache", + "arguments": [[], file.uri()], + }), + ); + client.did_open_file(&file); + let res = client.write_request( + "textDocument/codeAction", + json!({ + "textDocument": { + "uri": file.uri(), + }, + "range": { + "start": { "line": 2, "character": 6 }, + "end": { "line": 2, "character": 22 }, + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { "line": 2, "character": 6 }, + "end": { "line": 2, "character": 22 }, + }, + "severity": 8, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'assertReturnType'.", + "relatedInformation": [], + }, + ], + "only": ["quickfix"], + }, + }), + ); + assert_eq!( + res, + json!([ + { + "title": "Add missing function declaration 'assertReturnType'", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 2, + "character": 6, + }, + "end": { + "line": 2, + "character": 22, + }, + }, + "severity": 8, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'assertReturnType'.", + "relatedInformation": [], + }, + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": file.uri(), + "version": 1, + }, + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 6, + }, + "end": { + "line": 1, + "character": 6, + }, + }, + "newText": "import { ReturnType } from \"jsr:@denotest/types-file/types\";\n", + }, + { + "range": { + "start": { + "line": 3, + "character": 0, + }, + "end": { + "line": 3, + "character": 0, + }, + }, + "newText": "\n function assertReturnType(arg0: ReturnType) {\n throw new Error(\"Function not implemented.\");\n }\n", + }, + ], + }, + ], + }, + }, + ]) + ); +} + +#[test] fn lsp_code_actions_deno_cache_npm() { let context = TestContextBuilder::new().use_temp_cwd().build(); let mut client = context.new_lsp_command().build(); |