ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.59k stars 232 forks source link

Jump to definition with let-punning #1796

Open liam923 opened 4 months ago

liam923 commented 4 months ago

Consider the program:

let (let+) x f = List.map f x

let f x =
  let+ x in
  x

Locating x on line 4 gives:

$ ocamlmerlin single locate -position 4:7 -filename test.ml < test.ml | jq .value
"Already at definition point"

In my opinion, for this command it would be better to treat x as the variable bound on line 3 rather than the one on line 4. I believe that if a user is querying the definition point of x on line 4, they likely want the definition that isn't on that line.

voodoos commented 4 months ago

Yes I agree, there is a similar frustrating thing happening when asking for the definition of punned record arguments (but in that case it is less clear which is the correct answer).

It suspect that the interesting node is given a ghost location, so Merlin chooses the other one.