Skip to content

Feature request: Autocomplete variants as function parameters #203

Closed

Description

@cknitt

(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.

Activity

  1. added
    enhancement
    on Apr 30, 2021
  2. cristianoc commented on Apr 30, 2021

    @cristianoc
    Collaborator

    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.

  3. cknitt commented on Apr 30, 2021

    @cknitt
    MemberAuthor

    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

  4. added a commit that references this issue on May 8, 2021
  5. zth commented on Dec 29, 2022

    @zth
    Member

    Fixed in #665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions