summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/lsp_tests.rs207
-rw-r--r--cli/tests/testdata/lsp/initialize_params_hints.json102
2 files changed, 309 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index cc8625476..7dc5ff02d 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -1072,6 +1072,213 @@ fn lsp_hover_disabled() {
}
#[test]
+fn lsp_inlay_hints() {
+ let mut client = init("initialize_params_hints.json");
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": r#"function a(b: string) {
+ return b;
+ }
+
+ a("foo");
+
+ enum C {
+ A,
+ }
+
+ parseInt("123", 8);
+
+ const d = Date.now();
+
+ class E {
+ f = Date.now();
+ }
+
+ ["a"].map((v) => v + v);
+ "#
+ }
+ }),
+ );
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, Value>(
+ "textDocument/inlayHint",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ },
+ "range": {
+ "start": {
+ "line": 0,
+ "character": 0
+ },
+ "end": {
+ "line": 19,
+ "character": 0,
+ }
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ json!(maybe_res),
+ json!([
+ {
+ "position": {
+ "line": 0,
+ "character": 21
+ },
+ "label": ": string",
+ "kind": 1,
+ "paddingLeft": true
+ },
+ {
+ "position": {
+ "line": 4,
+ "character": 10
+ },
+ "label": "b:",
+ "kind": 2,
+ "paddingRight": true
+ },
+ {
+ "position": {
+ "line": 7,
+ "character": 11
+ },
+ "label": "= 0",
+ "paddingLeft": true
+ },
+ {
+ "position": {
+ "line": 10,
+ "character": 17
+ },
+ "label": "string:",
+ "kind": 2,
+ "paddingRight": true
+ },
+ {
+ "position": {
+ "line": 10,
+ "character": 24
+ },
+ "label": "radix:",
+ "kind": 2,
+ "paddingRight": true
+ },
+ {
+ "position": {
+ "line": 12,
+ "character": 15
+ },
+ "label": ": number",
+ "kind": 1,
+ "paddingLeft": true
+ },
+ {
+ "position": {
+ "line": 15,
+ "character": 11
+ },
+ "label": ": number",
+ "kind": 1,
+ "paddingLeft": true
+ },
+ {
+ "position": {
+ "line": 18,
+ "character": 18
+ },
+ "label": "callbackfn:",
+ "kind": 2,
+ "paddingRight": true
+ },
+ {
+ "position": {
+ "line": 18,
+ "character": 20
+ },
+ "label": ": string",
+ "kind": 1,
+ "paddingLeft": true
+ },
+ {
+ "position": {
+ "line": 18,
+ "character": 21
+ },
+ "label": ": string",
+ "kind": 1,
+ "paddingLeft": true
+ }
+ ])
+ );
+}
+
+#[test]
+fn lsp_inlay_hints_not_enabled() {
+ let mut client = init("initialize_params.json");
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": r#"function a(b: string) {
+ return b;
+ }
+
+ a("foo");
+
+ enum C {
+ A,
+ }
+
+ parseInt("123", 8);
+
+ const d = Date.now();
+
+ class E {
+ f = Date.now();
+ }
+
+ ["a"].map((v) => v + v);
+ "#
+ }
+ }),
+ );
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, Value>(
+ "textDocument/inlayHint",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ },
+ "range": {
+ "start": {
+ "line": 0,
+ "character": 0
+ },
+ "end": {
+ "line": 19,
+ "character": 0,
+ }
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(json!(maybe_res), json!(null));
+}
+
+#[test]
fn lsp_workspace_enable_paths() {
let mut params: lsp::InitializeParams = serde_json::from_value(load_fixture(
"initialize_params_workspace_enable_paths.json",
diff --git a/cli/tests/testdata/lsp/initialize_params_hints.json b/cli/tests/testdata/lsp/initialize_params_hints.json
new file mode 100644
index 000000000..1bab6e86d
--- /dev/null
+++ b/cli/tests/testdata/lsp/initialize_params_hints.json
@@ -0,0 +1,102 @@
+{
+ "processId": 0,
+ "clientInfo": {
+ "name": "test-harness",
+ "version": "1.0.0"
+ },
+ "rootUri": null,
+ "initializationOptions": {
+ "enable": true,
+ "cache": null,
+ "certificateStores": null,
+ "codeLens": {
+ "implementations": true,
+ "references": true,
+ "test": true
+ },
+ "config": null,
+ "importMap": null,
+ "inlayHints": {
+ "parameterNames": {
+ "enabled": "all"
+ },
+ "parameterTypes": {
+ "enabled": true
+ },
+ "variableTypes": {
+ "enabled": true
+ },
+ "propertyDeclarationTypes": {
+ "enabled": true
+ },
+ "functionLikeReturnTypes": {
+ "enabled": true
+ },
+ "enumMemberValues": {
+ "enabled": true
+ }
+ },
+ "lint": true,
+ "suggest": {
+ "autoImports": true,
+ "completeFunctionCalls": false,
+ "names": true,
+ "paths": true,
+ "imports": {
+ "hosts": {}
+ }
+ },
+ "testing": {
+ "args": [
+ "--allow-all"
+ ],
+ "enable": true
+ },
+ "tlsCertificate": null,
+ "unsafelyIgnoreCertificateErrors": null,
+ "unstable": false
+ },
+ "capabilities": {
+ "textDocument": {
+ "codeAction": {
+ "codeActionLiteralSupport": {
+ "codeActionKind": {
+ "valueSet": [
+ "quickfix",
+ "refactor"
+ ]
+ }
+ },
+ "isPreferredSupport": true,
+ "dataSupport": true,
+ "disabledSupport": true,
+ "resolveSupport": {
+ "properties": [
+ "edit"
+ ]
+ }
+ },
+ "completion": {
+ "completionItem": {
+ "snippetSupport": true
+ }
+ },
+ "foldingRange": {
+ "lineFoldingOnly": true
+ },
+ "synchronization": {
+ "dynamicRegistration": true,
+ "willSave": true,
+ "willSaveWaitUntil": true,
+ "didSave": true
+ }
+ },
+ "workspace": {
+ "configuration": true,
+ "workspaceFolders": true
+ },
+ "experimental": {
+ "testingApi": true
+ }
+ }
+}