From bbefceddb97c2eb7d8cd191dc15f3dc23ed5f6de Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sat, 29 May 2021 21:21:11 +1000 Subject: fix(#10765): lsp import fixes include extensions (#10778) Fixes #10765 --- cli/tests/integration_tests_lsp.rs | 51 +++++ cli/tests/lsp/code_action_params_imports.json | 54 +++++ .../lsp/code_action_resolve_params_imports.json | 26 +++ .../lsp/code_action_resolve_response_imports.json | 51 +++++ cli/tests/lsp/code_action_response_imports.json | 242 +++++++++++++++++++++ 5 files changed, 424 insertions(+) create mode 100644 cli/tests/lsp/code_action_params_imports.json create mode 100644 cli/tests/lsp/code_action_resolve_params_imports.json create mode 100644 cli/tests/lsp/code_action_resolve_response_imports.json create mode 100644 cli/tests/lsp/code_action_response_imports.json (limited to 'cli/tests') diff --git a/cli/tests/integration_tests_lsp.rs b/cli/tests/integration_tests_lsp.rs index 8e04cbb95..744b8d387 100644 --- a/cli/tests/integration_tests_lsp.rs +++ b/cli/tests/integration_tests_lsp.rs @@ -1425,6 +1425,57 @@ fn lsp_code_actions_deno_cache() { shutdown(&mut client); } +#[test] +fn lsp_code_actions_imports() { + let mut client = init("initialize_params.json"); + did_open( + &mut client, + json!({ + "textDocument": { + "uri": "file:///a/file00.ts", + "languageId": "typescript", + "version": 1, + "text": "export const abc = \"abc\";\nexport const def = \"def\";\n" + } + }), + ); + did_open( + &mut client, + json!({ + "textDocument": { + "uri": "file:///a/file01.ts", + "languageId": "typescript", + "version": 1, + "text": "\nconsole.log(abc);\nconsole.log(def)\n" + } + }), + ); + + let (maybe_res, maybe_err) = client + .write_request( + "textDocument/codeAction", + load_fixture("code_action_params_imports.json"), + ) + .unwrap(); + assert!(maybe_err.is_none()); + assert_eq!( + maybe_res, + Some(load_fixture("code_action_response_imports.json")) + ); + let (maybe_res, maybe_err) = client + .write_request( + "codeAction/resolve", + load_fixture("code_action_resolve_params_imports.json"), + ) + .unwrap(); + assert!(maybe_err.is_none()); + assert_eq!( + maybe_res, + Some(load_fixture("code_action_resolve_response_imports.json")) + ); + shutdown(&mut client); +} + #[test] fn lsp_code_actions_deadlock() { let mut client = init("initialize_params.json"); diff --git a/cli/tests/lsp/code_action_params_imports.json b/cli/tests/lsp/code_action_params_imports.json new file mode 100644 index 000000000..7a5824923 --- /dev/null +++ b/cli/tests/lsp/code_action_params_imports.json @@ -0,0 +1,54 @@ +{ + "textDocument": { + "uri": "file:///a/file01.ts" + }, + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + }, + { + "range": { + "start": { + "line": 2, + "character": 12 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'def'." + } + ], + "only": [ + "quickfix" + ] + } +} diff --git a/cli/tests/lsp/code_action_resolve_params_imports.json b/cli/tests/lsp/code_action_resolve_params_imports.json new file mode 100644 index 000000000..60178bbfe --- /dev/null +++ b/cli/tests/lsp/code_action_resolve_params_imports.json @@ -0,0 +1,26 @@ +{ + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingImport" + } +} diff --git a/cli/tests/lsp/code_action_resolve_response_imports.json b/cli/tests/lsp/code_action_resolve_response_imports.json new file mode 100644 index 000000000..6621c501f --- /dev/null +++ b/cli/tests/lsp/code_action_resolve_response_imports.json @@ -0,0 +1,51 @@ +{ + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import { abc,def } from \"./file00.ts\";\n" + } + ] + } + ] + }, + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingImport" + } +} diff --git a/cli/tests/lsp/code_action_response_imports.json b/cli/tests/lsp/code_action_response_imports.json new file mode 100644 index 000000000..e4d926bdd --- /dev/null +++ b/cli/tests/lsp/code_action_response_imports.json @@ -0,0 +1,242 @@ +[ + { + "title": "Import 'abc' from module \"./file00.ts\"", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import { abc } from \"./file00.ts\";\n" + } + ] + } + ] + } + }, + { + "title": "Add all missing imports", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingImport" + } + }, + { + "title": "Add missing function declaration 'abc'", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 3, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } + }, + "newText": "\nfunction abc(abc: any) {\nthrow new Error(\"Function not implemented.\");\n}\n" + } + ] + } + ] + } + }, + { + "title": "Import 'def' from module \"./file00.ts\"", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 2, + "character": 12 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'def'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import { def } from \"./file00.ts\";\n" + } + ] + } + ] + } + }, + { + "title": "Add missing function declaration 'def'", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 2, + "character": 12 + }, + "end": { + "line": 2, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'def'." + } + ], + "edit": { + "documentChanges": [ + { + "textDocument": { + "uri": "file:///a/file01.ts", + "version": 1 + }, + "edits": [ + { + "range": { + "start": { + "line": 3, + "character": 0 + }, + "end": { + "line": 3, + "character": 0 + } + }, + "newText": "\nfunction def(def: any) {\nthrow new Error(\"Function not implemented.\");\n}\n" + } + ] + } + ] + } + }, + { + "title": "Add all missing function declarations", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 1, + "character": 12 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "severity": 1, + "code": 2304, + "source": "deno-ts", + "message": "Cannot find name 'abc'." + } + ], + "data": { + "specifier": "file:///a/file01.ts", + "fixId": "fixMissingFunctionDeclaration" + } + } +] -- cgit v1.2.3