From 37292e74e1a986946ee73edaf81b05bc47b3a201 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 26 Aug 2023 01:53:44 +0100 Subject: fix(lsp): implement deno.suggest.completeFunctionCalls (#20214) Fixes https://github.com/denoland/vscode_deno/issues/743. ```ts const items: string[] = ['foo', 'bar', 'baz']; items.map // -> items.map(callbackfn) // auto-completes with argument placeholders. ``` --- We have our own setting for `suggest.completeFunctionCalls`, which must be enabled: ```js { "deno.suggest.completeFunctionCalls": true, // Re-implementation of: // "javascript.suggest.completeFunctionCalls": true, // "typescript.suggest.completeFunctionCalls": true, } ``` But before this commit the actual implementation had been left as a TODO. --- cli/tests/integration/lsp_tests.rs | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index e3fdcc281..d127ed31c 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -7721,6 +7721,84 @@ fn lsp_configuration_did_change() { client.shutdown(); } +#[test] +fn lsp_completions_complete_function_calls() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.did_open(json!({ + "textDocument": { + "uri": "file:///a/file.ts", + "languageId": "typescript", + "version": 1, + "text": "[]." + } + })); + client.write_notification( + "workspace/didChangeConfiguration", + json!({ + "settings": {} + }), + ); + let request = json!([{ + "enable": true, + "suggest": { + "completeFunctionCalls": true, + }, + }]); + // one for the workspace + client.handle_configuration_request(request.clone()); + // one for the specifier + client.handle_configuration_request(request); + + let list = client.get_completion_list( + "file:///a/file.ts", + (0, 3), + json!({ + "triggerKind": 2, + "triggerCharacter": ".", + }), + ); + assert!(!list.is_incomplete); + + let res = client.write_request( + "completionItem/resolve", + json!({ + "label": "map", + "kind": 2, + "sortText": "1", + "insertTextFormat": 1, + "data": { + "tsc": { + "specifier": "file:///a/file.ts", + "position": 3, + "name": "map", + "useCodeSnippet": true + } + } + }), + ); + assert_eq!( + res, + json!({ + "label": "map", + "kind": 2, + "detail": "(method) Array.map(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any): U[]", + "documentation": { + "kind": "markdown", + "value": "Calls a defined callback function on each element of an array, and returns an array that contains the results.\n\n*@param* - callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.*@param* - thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value." + }, + "sortText": "1", + "insertText": "map(callbackfn)", + "insertTextFormat": 1 + }) + ); + client.shutdown(); +} + #[test] fn lsp_workspace_symbol() { let context = TestContextBuilder::new().use_temp_cwd().build(); -- cgit v1.2.3