[ANN] Merlin 3.4.0 : introducing external configuration readers

I am glad to announce, on behalf of the Merlin team, the release of Merlin 3.4.0 which brings some major changes in the way configuration is handled.

As you might know, Merlin reads its configuration from the closest .merlin file to the source file being edited. These files tell merlin where to find other source files and build artifacts, but also which flags should be passed to the compiler, which syntax extensions are enabled and which packages are used by the project.

In this setting the configuration is the same for all the source files of a folder, regardless of their specificities. In other words, the configuration loaded for a single source file contains the union of the dependencies of this file and of all its siblings which is not an optimal behavior.

Starting with version 3.4.0 merlin will ship with two packages: merlin and dot-merlin-reader which, as the name suggests, reads configuration from .merlin files. Both are necessary for proper function.

When a .merlin file is present in the source folder the Merlin server will start a dot-merlin-reader process and communicate with it via standard input and output following a simple protocol. These processes are halted with the server.

This change should not have any visible impact on users’ workflows as long as the dot-merlin-reader binary is correctly installed and in the path. (which should be the case in opam-based setups)

This change in itself will not solve the granularity problem mentioned earlier, but it paves the way for such improvements: in a near-future Dune will stop generating .merlin files and Merlin will obtain file-based configuration directly from the build system using the same protocol as the one used by dot-merlin-reader.

Changelog

  • merlin binary
    • fix completion of pattern matchings with exception patterns (#1169)
    • delegate configuration reading to external programs via a simple protocol
      and create a new package dot-merlin-reader with a binary that reads
      .merlin files. (#1123, #1152)
17 Likes

Please ignore if this is highjacking the thread…

I’m wondering about the relation between merlin and ocaml-lsp. Are they complementary / mutually exclusive / will ocaml-lsp supersede merlin? If not, what part of Merlin functionality will never show up in ocaml-lsp?

Thanks!

Hi, that’s interesting, thanks. One question: will this make it possible for Merlin to support library dependencies e.g. for sources installed under ~/.opam? So e.g. would it be possible to jump-to-definition in a transitive opam dependency?

ocaml-lsp is actually built upon merlin, you could see it as another frontend to the binary, in addition to the emacs and vim ones.
However, IIUC, ocaml-lsp’s scope is a bit broader than that: it aims to be unified interface to merlin, ocamlformat, etc.

This doesn’t make it any easier (or harder) no. This just changes the way merlin receives its configuration, it doesn’t change whether the information is present or not.
Currently packages don’t install their .merlin file, so no information is available for merlin to do its work. That’s what you’d have to change (nowadays) for this to work.

Thanks. I’m actually a Vim user, and I’m wondering if I should continue using the built-in Vim front-end of Merlin or switch to using Merlin via ocaml-lsp + some LSP plugin for Vim, e.g. ALE.

The latter option could give me a simpler interface with a broader scope. But I don’t know if some Merlin functionality would then be missing. For instance, I currently I use :MerlinTypeEnclosing and :MerlinGrowEnclosing to browse semantic text blocks, and merlin_textobject to select them and I don’t know if that would still work.