-
-
Notifications
You must be signed in to change notification settings - Fork 114
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.
// Inlay hints for various expressions can be included here. | ||
|
||
let enter_expression = ({exp_desc, exp_type}: expression) => | ||
// Function parameter type hints |
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.
// Function parameter type hints |
| TExpLambda(bindings, _) => | ||
List.iter( | ||
({mb_pat, mb_loc}: match_branch) => { | ||
// Get Parameters |
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.
// Get Parameters |
| TPatTuple(args) => | ||
switch (resolve_typ(exp_type).desc) { | ||
| TTyArrow(typ_args, _, _) => | ||
// Iterate For Types |
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.
// Iterate For Types |
}, | ||
typ_args, | ||
); | ||
// Make Hints |
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.
// Make Hints |
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:
![image](https://private-user-images.githubusercontent.com/40705786/301921159-935d62e4-41ff-4343-9de3-5d1707a48863.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU4ODcxNzEsIm5iZiI6MTcyNTg4Njg3MSwicGF0aCI6Ii80MDcwNTc4Ni8zMDE5MjExNTktOTM1ZDYyZTQtNDFmZi00MzQzLTlkZTMtNWQxNzA3YTQ4ODYzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA5VDEzMDExMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWExNmM1YzliNzgzZWViYjQ1N2NkZTlkNzg3OTM2YjA4M2I4M2IzMTMyNzI2NGYyZjY2MWQ2MmIwZDJjNjRiZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Jtfyk3o7iBnqYWhbLHYz8rguTtn8IMl9uoHtm_eWNLo)