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

Leverage function contract information #1888

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Apr 12, 2024

Closes #1885.

When a function is annotated with a function contract, use this additional type information to enable completion in the LSP (and also use the domain as the type of the function's argument in the typing environment, even if we are in walk mode). Contract data are easy to fetch during typechecking when available and use them improve the developer experience by bringing in more static information.

I hesitated to updated the documentation about the fact that the typechecker is marginally smarter about function contracts, but I'm not sure yet we want to commit to it fully yet. Honestly I don't expect it to be used a lot in the wild, I mostly did it because it was virtually free (performance-wise and code complexity-wise).

= fun src =>
{
# TODO: we shouldn't need to type the first letter to get completion.
some_val = src.foo.b
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that for some reason, the completion doesn't fire if we don't start to typing a prefix of an existing field, while this doesn't happen for other kind of completion (for type-based completion for example, if you start to type std., you get a list of all available functions - same for a record literal, if you define record = {...} and then later type record., you get a full list - but here we get nothing until we type the first letter of a field). I'll open a separate issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it's the good old NLS can't handle some incomplete inputs. If I add an identifier at the end of this line, something like src_val = src.foo. dummy_value, which is then parsed correctly (because right now you can have a space between fields and the . character, for the best or the worst), then you get completion.

@yannham yannham requested review from jneem and vkleen April 12, 2024 09:11
@github-actions github-actions bot temporarily deployed to pull request April 12, 2024 09:12 Inactive
@yannham yannham force-pushed the feat/completion-fun-arg-contract branch from 00c4173 to bff01a5 Compare April 12, 2024 09:23
@github-actions github-actions bot temporarily deployed to pull request April 12, 2024 09:28 Inactive
core/src/typecheck/mod.rs Outdated Show resolved Hide resolved
When a function is annotated with a function contract, use this
additional type information to enable completion in the LSP (and also
use the domain as the type of the function's argument in the typing
environment, even if we are in walk mode). Contract data are easy to
fetch during typechecking when available and use them improve the
developer experience by bringing in more static information.
@yannham yannham force-pushed the feat/completion-fun-arg-contract branch from bff01a5 to 8681846 Compare April 12, 2024 16:23
@yannham yannham enabled auto-merge April 12, 2024 16:23
@github-actions github-actions bot temporarily deployed to pull request April 12, 2024 16:25 Inactive
@yannham yannham added this pull request to the merge queue Apr 12, 2024
Merged via the queue into master with commit 63edc96 Apr 12, 2024
5 checks passed
@yannham yannham deleted the feat/completion-fun-arg-contract branch April 12, 2024 16:51
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.

VSCode extension does not show hints for functions annotated with record contract
2 participants