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 function argument values #665

Merged
merged 29 commits into from
Dec 29, 2022
Merged

Complete function argument values #665

merged 29 commits into from
Dec 29, 2022

Conversation

zth
Copy link
Collaborator

@zth zth commented Dec 25, 2022

The first in likely a long series of PRs bringing in and refining the work done in #493, but little bit by bit.

This PR does the following:

  • Completes the expressions of labelled arguments or unlabelled arguments in function applications.
  • Currently completes booleans, options and variants. The rest of the relevant types (polyvariants, records, tuples, etc) will be completable as well in due time.

There are caveats that I've added comments for in the PR.

The next step will be getting support for snippets in completion items in, so we can intelligently move the cursor for the user into payloads of constructors etc. That'll come in a separate PR.
After that, completing polyvariants.
Then the same work as in this PR, but for JSX props.

@zth zth requested a review from cristianoc December 25, 2022 18:31
@@ -1455,6 +1455,131 @@ let getOpens ~debug ~rawOpens ~package ~env =
(* Last open takes priority *)
List.rev resolvedOpens

let getArgs ~env (t : Types.type_expr) ~full =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This one is mostly copied from a pre-existing fn, but with identifying what type of argument is found (labelled or unlabelled).

Comment on lines 1539 to 1540
~name:
(constructor.cname.txt
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bonus points @cristianoc - can we somehow figure out if we need to qualify the constructor here? Not something we need to do now, but something worth thinking about for the future.

Comment on lines 1559 to 1564
Completion.create ~name:"None"
~kind:(Label (t |> Shared.typeToString))
~env;
Completion.create ~name:"Some(_)"
~kind:(Label (t |> Shared.typeToString))
~env;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm going to improve this a lot soon. Mainly 2 things:

  1. Some(_) will eventually be a snippet Some($1:_), which means that the cursor is automatically positioned in the option payload (so we can keep completing the option value)
  2. If the inner type is "small" enough (bool, variant with few payloads, etc), we can expand those into the list directly, so that instead of None/Some(_), it'd be None/Some(true)/Some(false) for bools, etc.

@zth zth changed the title Complete named arguments Complete function argument values Dec 25, 2022
analysis/src/CompletionBackEnd.ml Outdated Show resolved Hide resolved
analysis/src/CompletionBackEnd.ml Outdated Show resolved Hide resolved
@zth zth merged commit 2efec0b into master Dec 29, 2022
@zth zth deleted the complete-named-arguments branch December 29, 2022 10:30
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