summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration_tests_lsp.rs51
-rw-r--r--cli/tests/lsp/code_action_params_imports.json54
-rw-r--r--cli/tests/lsp/code_action_resolve_params_imports.json26
-rw-r--r--cli/tests/lsp/code_action_resolve_response_imports.json51
-rw-r--r--cli/tests/lsp/code_action_response_imports.json242
5 files changed, 424 insertions, 0 deletions
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
@@ -1426,6 +1426,57 @@ fn lsp_code_actions_deno_cache() {
}
#[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");
client
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"
+ }
+ }
+]