Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete polyvariants #283

Closed
zth opened this issue Jul 5, 2021 · 7 comments
Closed

Autocomplete polyvariants #283

zth opened this issue Jul 5, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@zth
Copy link
Collaborator

zth commented Jul 5, 2021

This would really be a killer feature that'd bring the experience closer to what TS offers.

Basically, what I'm looking for is something like:

switch somePolyVariant {
  | #<list here of possible polyvariants>
}

Would this type of feature be easy or hard to implement? I understand there's multiple layers to this, like polyvariants with payloads, polyvariants with escaped names, open polyvariants etc. But just the "basic" case of autocompleting possible members of the polyvariant when they're known would be a big help.

@cristianoc cristianoc added the enhancement New feature or request label Jul 5, 2021
@cristianoc
Copy link
Collaborator

This would indeed be pretty valuable.

Requires:
1 Triggering autocomplete on #.
2 Finding whether the context is a switch statement, and if it is, find the expression switched over.
3 Find the type of the expression.
4 From the type, extract the list of variants, and populate the list.

The main relevant part is 2. The rest is very similar to other cases of autocomplete.

@cristianoc
Copy link
Collaborator

Notice because of type inference, the type of the expression switched over might not help.

The same feature would provide more consistent value, without gotchas, on ordinary variants.

@cristianoc
Copy link
Collaborator

This issue can be merged with #253.

@cristianoc
Copy link
Collaborator

Merged into #253.

@zth
Copy link
Collaborator Author

zth commented Jul 5, 2021

I think this would also be valuable for assignments. Especially in GraphQL, where enums are usually modelled as polyvariants. So, kind of:

mutate(~variables={status: #<list of possible enum values>

But, that particular example is tightly bound to completion on record fields when constructing them too I guess, which is mentioned in this issue: #120

@cristianoc
Copy link
Collaborator

Not sure it's related to record fields. The example is, but the general feature does not seem to be.
The general feature being: autocomplete (poly) variants based on type context. The context can be used to infer the expected type, and the expected type used to complete the variant.
In that sense, the switch example is also just a special case. Where the switch provides a type context.

When no type context exists, such as let x = #, perhaps one could try with any variant in scope. Though that might be noisy/slow. To be seen.

@zth
Copy link
Collaborator Author

zth commented Jul 5, 2021

Ahh right, got it! Since polyvariants map to strings and ints so nicely now, I think there are a ton of usage of polyvariants for interop etc where a regular variant might actually be more "correct", but a polyvariant is used because it's zero cost. So for all of those cases, this type of feature would be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants