ocaml / ocaml-lsp

OCaml Language Server Protocol implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

oleksandr-oksenenko opened this issue · 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?

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

commented

@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 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!
commented

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

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
commented

Right, this is a usual case of "Dune @ALL target does not build cmt files for executable" (ocaml/dune#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.

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
commented

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

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