-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
feat(lsp): Add Inlay types #2005
base: main
Are you sure you want to change the base?
Conversation
7925321
to
fb31ce3
Compare
c8c64f5
to
bd9892e
Compare
Here I'd want us to hide hints for function definitions—they're long and get in the way of the function arguments, which already have hints on them/show much of the same information. It'd also be cool to have hints on destructures, but that could maybe come in a later PR. |
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.
I'm going to approve because the code looks good, but subject to the request to be able to hide/show them as a setting
I made that change, I also implemented a cli flag I think we should leave the destructures for a future pr. I also plan on coming back and adding type hints on function calls that show the label in a future pr. |
@spotandjake can't you just disable inlay hints in the client, and then users can decide if they want them or not? What is the purpose of the flag? |
As we add more inlays, such as parameter hints. and other inlays I can see cases where the user might want to dissable the type hints but keep the others, because of how verbose the type hints are. |
}; | ||
|
||
let enter_binding = ({vb_pat, vb_expr}: value_binding, toplevel: bool) => | ||
if (!toplevel) { |
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.
Nit: cut down on the condition nesting, perhaps if (!toplevel && toggle_type_hints)
and then
switch (vb_pat) {
| {pat_extra: [], pat_desc: TPatVar(_, {loc}) => ...
| _ => ()
}
}; | ||
| _ => () | ||
} | ||
| _ => () |
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.
Would this ever be possible? If not should we do failwith("Impossible: ...")
?
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.
It seems as though there is a case where it can be a constructor.
List.combine(args, argument_typs), | ||
); | ||
}; | ||
| _ => () |
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.
I think this would never be possible. Should we do failwith("Impossible: ...")
?
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.
That case can be hit if we are omitting the annotation because typ
is None
typ_args, | ||
); | ||
// Make Hints | ||
if (List.length(argument_typs) == List.length(args)) { |
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.
Would this ever be false?
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.
I don't think so but I also think it makes sense to ensure we don't make a change somewhere else in the compiler and break this. I am going to add a failwith("Impossible")
though if it is the not equal.
List.map( | ||
((arg, typ: Types.type_expr)) => | ||
switch (arg) { | ||
| Default(_) => None |
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.
Could you expand on this? I'm seeing in your screenshot that the default argument has an inline hint on it
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.
The default hint comes from the binding pass, if this is enabled it shows : Option<_>
after the value.
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.
Played with this locally and I love how this looks and feels! I understand your point about having the command line flag, but I feel like we should wait to add that when we actually are adding more hints and want them to be controlled separately and not commit to having the flag right now.
b53d0ad
to
e86c6f2
Compare
After discussion in discord instead of the command line flag it would make more sense to use: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize but I think we can defer it to a separate pr when we are going to add more inlay hint types. The final thing this pr needs is test but I don't quite understand how the new lsp tests work yet. |
This pr adds inlay types which closes #1359.
This pr is marked as a draft as there is still some work that needs to be done:
Function
, and show the return type and param types on the actual lambda)Tuple patterns
,record patterns
,constructor patterns
Current Demo Below: