From 7d78f58187cdcb9bed632992cde347fd5f3c83eb Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sun, 16 Oct 2022 13:39:43 +1100 Subject: feat: support inlay hints (#16287) Closes: #11853 --- cli/tests/integration/lsp_tests.rs | 207 +++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) (limited to 'cli/tests/integration') 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 @@ -1071,6 +1071,213 @@ fn lsp_hover_disabled() { shutdown(&mut client); } +#[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( -- cgit v1.2.3