ocaml-lsp icon indicating copy to clipboard operation
ocaml-lsp copied to clipboard

Show specialized types on hover

Open voodoos opened this issue 4 weeks ago • 3 comments

In emacs / vim modes for Merlin the ability to grow / shrink enclosing has an interresting side effect: often the first two enclosing are identical but the second one shows the most general type while the second one show the specialized type.

For example, given the following code:

let f : 'a -> 'a = fun x -> x
let _ = f 4

Querying Merlin on the usage of f line 2 first result in 'a -> 'a, and querying the next enclosing shows the specialized type int -> int. However, in ocaml-lsp, there is no way to get that second answer since the on_hover query always consider the first enclosing.

I feel like I am more often interested in the specialized type because it also gives me information on the type of the actual parameters. I guess this is a matter of context and preference, but I generally find the current behavior not satisfying.

We might soon be able to use a custom query that would allow editors to reproduce the classic merlin enclosing behavior, but I am wondering whether we should change the default behavior for the on_hover query...

We could also show both types at the same time ?

voodoos avatar Jun 26 '24 13:06 voodoos