rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

Feature request: Autocomplete variants as function parameters

Open cknitt opened this issue 3 years ago • 2 comments

(Somewhat related to #120 which is about autocompletion of variants in the case of pattern matching.)

There is another common situation where it would be nice to have autocompletion for variants:

Say I have a variant

type action =
  | A
  | B
  | C

and a dispatch function with signature action => unit.

Now if I type dispatch(, it is known that the parameter is of type action and it would be great if A, B and C could be autosuggested.

cknitt avatar Apr 29 '21 17:04 cknitt

This looks very specific: assume there's a single unlabeled argument of type variant. Then try to autocomplete. Feels like we need a more general proposal for this.

cristianoc avatar Apr 30 '21 03:04 cristianoc

I just wanted to give a simple example for a common use case. Yes, it can be generalized in various ways, e.g. to multiple arguments, labelled arguments, uncurried invocation etc.

It also can be generalized to other situations where we know that a variant type is expected, e.g.

let action: action = 

It also can be generalized to functions with a record parameter, e.g.

type user = {
  firstName: string,
  lastName: string,
}

let fullName = ({firstName, lastName}) => firstName ++ " " ++ lastName

fullName(

This sort of things generally works very well in TypeScript:

Bildschirmfoto 2021-04-30 um 07 42 26 Bildschirmfoto 2021-04-30 um 07 42 42

cknitt avatar Apr 30 '21 05:04 cknitt

Fixed in https://github.com/rescript-lang/rescript-vscode/pull/665

zth avatar Dec 29 '22 12:12 zth