ocaml / ocaml-lsp

OCaml Language Server Protocol implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Show specialized types on hover

voodoos opened this issue · 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 ?

Yes! I think that having a nice pretty printer (ie: 'a -> 'a \n int -> int) for "applied/specialized" function can be very useful!

Sure, you can experiment with it. No particular preference on what's the best default here.

However, in ocaml-lsp, there is no way to get that second answer since the on_hover query always consider the first enclosing.

Another idea that may or not be feasible: include a markdown link that can be followed to see the expanded definition.