OCamlPro / ocp-index

Easy access to the interface information of installed OCaml libraries for editors like Emacs and Vim.
http://www.typerex.org/ocp-index.html
Other
62 stars 25 forks source link

ocp-index locate returns the wrong location #167

Open mlemerre opened 9 months ago

mlemerre commented 9 months ago

Hi,

First, thank you for ocp-index. I don't know why I did not know the tool before, it should definitively be part of the tools officially recommended!

One issue though is that it does not return the correct locations. If I type:

$ ocp-index locate Z.one
/home/matthieu/.opam/4.14.1+BER/.opam-switch/build/zarith.1.13/z.mli:62:0

this is incorrect.

If I look at the doc, the location where z.mli is looked up is obtained by opam var lib, whose value is

/home/matthieu/.opam/4.14.1+BER/lib

in my case.

And indeed, if I do

$ ocp-index locate Z.one --no-opamlib

Then there is no result.

So my guess is that there is some changes in the path done by ocp-index, which should return instead

./lib/zarith/z.mli

or

./.opam-switch/sources/zarith.1.13/z.mli

Is there something wrong in my setup? I only did opam install ocp-index.

Thanks Matthieu

lthls commented 9 months ago

It is, unfortunately, the expected result. To resolve Z.one, ocp-index looks up the .cmt and .cmti files available in the current setting that match the query. It finds /path/to/opam/switch/lib/zarith/z.cmti, which is more or less a marshalled version of the typed AST for z.mli, including locations. But since z.cmti was generated during installation of zarith, by compiling the file z.mli in the temporary build folder /path/to/opam/switch/.opam-switch/build/zarith.version/, that is the location stored in the AST, and the only one that ocp_index can report. Note that ocp-index does not try to read or find source files, so the existence of a z.mli file in the library directory has no impact on what the tool will report.

One possible workaround is to keep build directories when installing opam packages (either by passing the -b or --keep-build-dir flag, or setting the environment variable OPAMKEEPBUILDDIR to 'true'). This will ensure that the locations stored inside the installed cmti files still exist.

Finally, if you have a copy of the zarith sources somewhere (through opam source, for example) you can ask opam to install the zarith package from these sources and use the source directory to build, which will increase the chance of ocp-index finding the right source files. The command would look like (cd /path/to/zarith/sources && opam install . --inplace-build).