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

Complete via TypeAtPos #808

Merged
merged 5 commits into from
Aug 17, 2023
Merged

Complete via TypeAtPos #808

merged 5 commits into from
Aug 17, 2023

Conversation

zth
Copy link
Collaborator

@zth zth commented Aug 16, 2023

We've previously handled completion for let bindings where there's also a type annotation:

type user = {
  name: string,
  age?: int
}

let user: user = {name: "Test", <com>}

This gives completion because we look up that we're in a record called user.

However, this same snippet below should be valid if we've saved and compiled, even if there's no explicit type annotation:

type user = {
  name: string,
  age?: int
}

let user = {name: "Test", <com>}

let user will have the inferred type of user. But, this hasn't been picked up before.

This PR fixes that, by trying to complete for "the type at the position of the let binding" if there's no explicit type annotation. The cool part is that the compiler is quite liberal with assigning a type to the let binding even if it's not fully compiling. So, you could write a record expression without a type annotation, save and let the compiler infer what record it thinks you're trying to construct, and then get completions for that, even if the thing you're trying to construct isn't complete/doesn't type check yet.

Will make for a nicer DX when using inference.

@zth zth merged commit 29b377b into master Aug 17, 2023
5 checks passed
@zth zth deleted the complete-via-typeatpos branch August 17, 2023 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants