microsoft / TypeScript

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

Parameter completion for arrow/anonymous functions #51427

Open Ocraftyone opened 1 year ago

Ocraftyone commented 1 year ago

Auto complete the parameters of anonymous functions. JavaScript and most other languages already name the parameters when the function is defined and you can see these names while you are writing the function, but why not complete the whole statement, or at least complete the names when in the parentheses.

JavaScript already knows the param names image

How IntelliJ handles it image image

llllvvuu commented 11 months ago

Currently it seems like the parameter information is received upon completion resolution and not in the completion list. So there's not enough upfront information to commit to making the menu item a snippet, but you also can't change it later.

I wonder if actually pulling up information (or even just the bare minimum to determine whether it is a type that we will be able to query for a snippet later) about all the variables in the completion list will be a performance hit.

zardoy commented 9 months ago

So there's not enough upfront information to commit to making the menu item a snippet, but you also can't change it later.

@llllvvuu , if we talk about the language service plugins, there is enough information when you request a completions list. This became possible since TS 5.0, where you can get a type of any completion, so you can resolve all method signature snippets in the list, you can look at the real implementation: https://github.com/zardoy/typescript-vscode-plugins#method-snippets . However, the main issue here is that TypeScript doesn't fully support partial completion resolving eg getCompletionEntryDetails doesn't support a way of resolving insertText of the requesting completion, so you can't compute this method snippet at a later stage, which is a big performance hit. On the other hand, this enables method signature preview in every completion, which is just super handy!