microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
98.97k stars 12.28k forks source link

Move 'completeFunctionCalls' into TypeScript language service #51758

Open mjbvz opened 1 year ago

mjbvz commented 1 year ago

Problem

In VS Code, the javascript.suggest.completeFunctionCalls and typescriptscript.suggest.completeFunctionCalls settings make VS Code automatically add parens and argument snipper stops when you complete a function call. For example:

function foo(a, b, c) { }

fo|

Result inL

function foo(a, b, c) { }

foo(a, b, c)

Users generally like this feature but we cannot properly implement it on the VS Code side as we don't have enough context about the completion or where the completion is occurring. This has resulted in number of bugs that severely limit the usefulness of this feature

Request

I proposed that we move the logic from completeFunctionCalls into the TypeScript server. Not only does TS have more information about the context of the completion and would therefore be better able to implement this, adding this to TS server means that feature could also be used by other editors, including VS

For this, we may want to take inspiration for the snippets we return for overload functions. With these, we return the normal function name completion along with the full overload completion. Returning both completions for completeFunctionCalls would be useful as it is sometimes not possible to tell if the user meant to pass around the function as an object or call the function

zardoy commented 1 year ago

I think it's essentially duplicate of https://github.com/microsoft/TypeScript/issues/51427

Returning both completions for completeFunctionCalls would be useful as it is sometimes not possible to tell if the user meant to pass around the function as an object or call the function

Also thanks for exposing tsApi.onCompletionAccepted as this is just ideal place for handling this case (instead of putting it to insertText of completion). That's how I implemented it in my plugin: https://github.com/zardoy/typescript-vscode-plugins#method-snippets