Skip to content

Letting merlin locate go to stuff in .opam

Wilfred Hughes edited this page Jun 30, 2018 · 1 revision

To use merlin-locate to go to the source of things installed with opam, you first of all need to keep the source around when installing, and let opam create .cmt files:

export OPAMKEEPBUILDDIR=true
export OCAMLPARAM="_,bin-annot=1"

(You might want to put those lines in your ~/.bashrc if you always want this to go for all your opam stuff.) Then install your package, or reinstall if you already installed without these variables set. So if you already installed pcre without bin-annot/KEEPBUILDDIR, you can do

opam reinstall pcre

Now if you do find ~/.opam -name '*.cmt' you should see a bunch of .cmt files, for any package you want "locate" to go to, you'll need to put it into your .merlin using both S and B (as well as the PKG line of course). So for pcre, your .merlin might need something like this (replacing with the correct version numbers and username):

PKG pcre
S /home/me/.opam/4.02.1/build/pcre-ocaml.7.1.2/_build # This should not be necessary as of merlin 2.
CMT /home/me/.opam/4.02.1/build/pcre-ocaml.7.1.2/_build

If you want all your sources to be available in your .merlin, https://gist.github.com/unhammer/c1ac7320141f09ac38e0 will auto-create a .merlin for you – with this you should be able to use merlin-locate on symbols like Pcre.replace and go straight to the definition.

(Follow https://github.com/ocaml/merlin/issues/235 on making merlin do more of this automatically.)