-
Notifications
You must be signed in to change notification settings - Fork 143
Add autocompletion for labelled args #1564
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
base: master
Are you sure you want to change the base?
Conversation
match context with | ||
| `Application { Query_protocol.Compl.labels = _; argument_type } | ||
when not (is_polymorphic_type argument_type) | ||
&& not (is_primitive_type argument_type) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this, perhaps it'd be useful to get e.g. 0
or false
for primitive types as well?
Thank you @lessp, that's an interesting proposition. To clarify a bit, this PR does two things:
Item 1 seems all-right when calling a function with a labelled parameter, this might actually be a good thing, but we should make sure that it is acceptable to trigger completion on all other usages of About 2, I wonder how often this is going to be useful in practice, once we leave the realm of small handcrafted examples ? I think it's worth experimenting though, maybe by having this behavior configurable. Also, it feels like this should work for every function arguments, not only labelled ones... and maybe other places too ? @xvw, @rgrinberg, do you have an opinion on this ? |
Thanks for leaving your thoughts @voodoos! I primarily thought I'd open up the discussion on this.
Right, I realise one would have to be wary of where we'd trigger, and I don't want to get ahead of anything, but ideally we'd also be able to trigger for
Yes, although I did realise that these are available without having to query merlin if you add e.g. ![]()
Can you expand on the statement below?
The actual need for this sprung out of it being non-obvious what an argument takes, especially when the type itself is defined a few indirections away. In my experience this becomes even more useful in a larger code-base. The behaviour is something that I miss when switching between other popular languages like TypeScript. For e.g. (* style_vars.ml *)
type padding =
| NoPadding
| Small
| Medium
| Large
| Custom of int
type size =
| Small
| Medium
| Large
type z_layer =
| Tooltip
| Popover
| Modal
| ExpandableRow
| Above of z_layer
(* row.ml *)
let create ~(padding: Css.padding) ... = ...
(* consumer.ml *)
let my_row = Row.create ~padding: As for e.g. records. What is your current approach to constructing the person for something like the following? (* some_file.ml *)
type employee = {
name: string;
email: string;
}
type customer = {
name: string;
age: int
}
... additional types
(* some_consumer.ml *)
let x = create ~customer: I'd argue that even if you just see the auto-completion, you'd know immediately what arguments you'd need to provide. The alternative as I see it would be to look at the hover information, see something like
|
Hi ! |
This adds auto-completion for labelled arguments. I decided to disable them for primitives like
int
orbool
as it felt a bit iffy, but it'd work for those too. For int merlin seems to suggest0
etc.Examples
Here's an example with variants:
CleanShot.2025-10-14.at.13.30.03.mp4
And records:
CleanShot.2025-10-14.at.13.35.27.mp4