VSCode Ocaml+Reason extension cannot find merlin binary

I’ve re-installed opam from scratch, after doing a rm -rf ~/.opam, and then installed a switch based on 4.14.0.
The problem I’m encountering now is that VSCode “cannot find merlin binary” (even though which ocamlmerlin returns the correct answer /Users/jonathandoyle/.opam/four_fourteen/bin/ocamlmerlin in any terminal).

What is going on here ?

The recommended Ocaml Platform extension does not use ocamlmerlin but ocaml-lsp-server. Maybe:

  • You have another ocaml extension active that does need ocamlmerlin. In that case you can simply disable it.
  • You forgot to opam install ocaml-lsp-server and the error message is wrong.

Indeed, and this package is “Reason+OCaml” as indicated in the error message. I disabled it and the error message is gone. Thanks for the help

OCaml Platform and ocaml-lsp-server are installed indeed.
My troubles are not finished, though : the “goto definition” feature does not work across files (although it does work inside a single file and type hints work as well).

Do you build your project with Dune ?
Merlin requires project’s specific configuration and build artifacts to function properly.
The easiest way to get these is to build your project with Dune.

So if you already have dune files in your project you probably just need to run dune build once.

1 Like


Well then, I guess I need to learn about those and how to specify them to merlin without dune.
I already have a .merlin file in my project, what else do I need?

(update : or perhaps I can try to “dunify” a nondune project, if that’s simple to do).

Ok, the problem is that ocaml-lsp-server does not load .merlin files anymore by default.

I think there is a flag for that (--fallback-read-dot-merlin). But, looking at the settings panel of the vscode plugin, I don’t see where this flag can be added.

@rgrinberg @Ulugbek : what is the intended way to use that flag ? Also, it would be very useful if ocaml-lsp-servercould hint that user might want to use that fallback flag, and the vscode extension have an easy-to-toggle setting.

1 Like

Also, I noticed that opam tells me that ocaml-lsp-server is installed with version 1.14.1, and that I have a ~/.opam/four_fourteen/lib/ocaml-lsp-server directory containing a few files (dune-package, META and opam), but I don’t have an ~/.opam/four_fourteen/bin/ocaml-lsp-server binary. Shouldn’t there be one ?

Some users still rely on .merlin for some setups not yet supported by dune. Melange in particular is still in this state (temporarily).

I’d rather not expose this flag at all to end users because I consider writing .merlin files by hand to be an anti-pattern. @jonathandoyle is better served by building his project with dune.

If you say so. So far I don’t consider my OCaml projects to be likely to be useful to other people, which is why I never bothered to build them with dune (and so far I don’t see what benefits dune brings to amateurs only programming for themselves like me).

Is it simple to “dunify” a large product originally created and maintained without dune ?

Using dune does not require you to share your project with anybody.

About as simple as writing a correct .merlin file

There are use-cases for not using Dune. I can see at least three:

  • Doing small maintenance tasks on big and old projects that do not use Dune and for which the time spent to dunify them is not worth the benefits.
  • CS courses were teachers often force students to do manual compilation and write makefiles to show how things work.
  • Users who want to experiment with other build system or are stuck with a legacy project.

(and we have seen some other edge-cases that arised in issues)

1 Like

For large projects, writing .merlin files and verifying they work correctly is just as much work as porting them to dune.

This is an interesting use case. Though it seems like it would be just as easy for users to write a dune file to describe their project in parallel to their build system. It would be useful to both verify their makefiles work and get free editor support

I should clarify that I’m not against supporting .merlin files by default in principle. I just dislike how they are generated in the source directory. I’d be willing to support any build system that generates this stuff in a dedicated build directory.