How to set up goto-definition with OCaml 5 + merlin in doomemacs

Hello, OCaml community.
I’m using doomemacs with emacs packages that are pinned as tuareg(1d53723e39f22ab4ab76d31f2b188a2879305092), merlin(8404f96693727f7b0edc0d0b14db57843d79e27b) and merlin-company(8404f96693727f7b0edc0d0b14db57843d79e27b).
I’m trying to test the development environment for OCaml 5. I picked riot for the testbed. I’ve installed the following compiler/packages:

  • ocaml-base-compiler: 5.1.1
  • merlin: 4.16-501
  • dune: 3.16.0

After installing the dependencies of riot, I’ve successfully built the riot project. But it failed when I opened a source file (e.g. riot/riot/riot.ml) and tried to locate the specific module by merlin-locate. This whole process worked smoothly when I tried with OCaml 4.13.1 version with proper dune(3.6.2) and merlin(4.7-413).

I’ve also noticed that merlin-eldoc complains that “eldoc error: (error merlin: … seems to be compiled with a version of OCaml that is not supported by Merlin.)” but I suspect that merlin 4.16-501 supports OCaml 5.1.1+, so this is quite confusing.

Where do I start to investigate? Has anyone encountered similar issues with OCaml 5+?
Many thanks.

Are you using the merlin compiled with 5.1.1? It appears you may be using the merlin binary compiled with an older version of OCaml. You can check the value of merlin-command to see which binary is being used. If it’s value is opam, using the right opam switch should ensure that you are using the correct version of merlin. (You can set the opam switch with opam-switch-mode’s opam-switch-set-switch)

2 Likes

Thank you very much!!
As you said, my merlin-command was set to opam and the root cause was using the wrong opam switch.
Thanks for letting me know about the great tool opam-switch-mode and after switching to the right opam switch, everything works just fine.
Thank you so much!

1 Like

Great! I’m glad everything works for you.

I’ve an open PR to make opam-switch-mode a part of the doom emacs OCaml configuration, that I’ve just bumped up…

1 Like