ocaml-lsp icon indicating copy to clipboard operation
ocaml-lsp copied to clipboard

Jump to definition request fails with Merlin "Several source files in your path" error

Open oleksandr-oksenenko opened this issue 2 years ago • 10 comments

I'm trying to learn OCaml created a simple project using dune init proj, added core as a dependency and trying to go to the definition of Set in the following code:

open Core

module S = Set

let () = print_endline "Hello, World!"

and it fails with the following error:

'Locate' query to merlin returned error: File_not_found: Several source files in your path have the same name, and merlin doesn't know which is the right one: /Users/oleksandr.oksenenko/.opam/5.1.0/lib/core/set.mli, /Users/oleksandr.oksenenko/.opam/5.1.0/lib/core/set.ml, /Users/oleksandr.oksenenko/.opam/5.1.0/lib/base/set.mli, /Users/oleksandr.oksenenko/.opam/5.1.0/lib/base/set.ml, /Users/oleksandr.oksenenko/.opam/5.1.0/lib/ocaml/set.mli, /Users/oleksandr.oksenenko/.opam/5.1.0/lib/ocaml/set.ml"

I found the following issue in Merlin, however, it seems to be fixed a long time ago.

I'm using latest versions of neovim and ocaml-lsp (1.16.2) on OCaml 5.1.0, however, i encountered the same issue with 4.14.1.

Am i missing something?

oleksandr-oksenenko avatar Sep 23 '23 10:09 oleksandr-oksenenko

@voodoos do you happen to know what could cause this?

ulugbekna avatar Sep 24 '23 22:09 ulugbekna

@oleksandr-oksenenko, thanks for the report!

Can you check if your the project has been built at least once (dune build @all) ? Are they any error reported in the buffer ?

voodoos avatar Sep 25 '23 09:09 voodoos

@voodoos thanks for reply! Please let me know if i can provide any additional details. The project builds and runs just fine:

~/code/ocaml_playground_2 via 🐫 v5.1.0 (5.1.0) took 16s 
❯ dune build @all
~/code/ocaml_playground_2 via 🐫 v5.1.0 (5.1.0) 
❯ dune exec -- bin/main.exe                 
Hello, World!

oleksandr-oksenenko avatar Sep 25 '23 11:09 oleksandr-oksenenko

Could you give me the output of ls _build/default/bin/.merlin-conf and ls _build/default/bin/.*.objs/byte ?

voodoos avatar Sep 25 '23 11:09 voodoos

The first one produces

❯ ls _build/default/bin/.merlin-conf 
exe-main

I updated the second command a bit to find what you want (i think, the dir is called .main.eobjs/):

❯ ls _build/default/bin/.*objs/byte
dune__exe__Main.cmi  dune__exe__Main.cmti

oleksandr-oksenenko avatar Sep 25 '23 11:09 oleksandr-oksenenko

Right, this is a usual case of "Dune @all target does not build cmt files for executable" (https://github.com/ocaml/dune/issues/3182).

Some context: Dune generates both a configuration for Merlin and ask the compiler to write cmt files that are needed for some Merlin feature like locate. However some targets do not trigger the building of cmt files.

I think you should be good with dune build @check that is a target that explicitly ask Dune to build all merlin-needed files. (you cant check afterwards the presence of cmt files with ls _build/default/bin/.*objs/byte.

voodoos avatar Sep 25 '23 12:09 voodoos

Hm, I ran dune build @check and it fails with the same error. The contents of the byte directory:

❯ ls _build/default/bin/.main.eobjs/byte
dune__exe__Main.cmi  dune__exe__Main.cmo  dune__exe__Main.cmt  dune__exe__Main.cmti

oleksandr-oksenenko avatar Sep 25 '23 12:09 oleksandr-oksenenko

Right, I was able to reproduce, I will have a look. Thanks for all the information !

voodoos avatar Sep 25 '23 12:09 voodoos

Awesome, thanks! JFYI it happens not only with core, for instance i had the same issue with cohttp modules.

oleksandr-oksenenko avatar Sep 25 '23 13:09 oleksandr-oksenenko