Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merlin complains about a missing module in the same project

I am new to Ocaml and just setting up my dev environment with emacs, merlin and flycheck. Everything works more or less expected except one thing : merlin doesn't seem to be able recognise the dependencies between the modules in the same project.

e.g. I have a test project with two modules: main.ml and awesome.ml.

here is my main.ml which references the second module awesome.ml

(* main.ml *)
open Core
module A = Awesome
let _ =
   Printf.printf "hello \n Converted to string we get: %s\n"
     (A.str_of_t (A.succ A.one_t));

here is awesome.ml:

(* awesome.ml *) 
type t = int
let one_t = 1
let succ i = i + 1
let str_of_t = string_of_int

when I send main.ml buffer to evaluate into utop with utop-eval-buffer function, I am getting an error: "Error: Unbound module Awesome"

I have .merlin in the root of the project which has S instruction. I know it is found by merlin as it doesn't complain about "open Core"

S src
PKG core lwt ounit
B _build/src
B +threads

here is my _tags:

<src/**>: include
<src/**>: package(oUnit), package(core)
true:thread

the regular project compilation with ocamlbuild works fine, no errors. here is Makefile

## Makefile
default: main
main: main.native

test: test.native

%.native:
   ocamlbuild -use-ocamlfind $@
   mv $@ $*

.PHONY: test default

any ideas why Awesome module is not recognised in utop or this is expected behaviour?

like image 701
Roman Shestakov Avatar asked Jul 19 '15 09:07

Roman Shestakov


Video Answer


1 Answers

Merlin will see other modules once you have compiled them (in fact, once you have compiled its interfaces). So given your .merlin is correct it will see everything after you run compilation. Your files should indeed be in a src folder, i.e., your project layout, based on your .merlin file should look like this:

Makefile
.merlin
src/
   awesome.ml
   main.ml

This is not a required layout, but this is the one, that you described to Merlin. The reason, why I suspect that it is not the same, is your Makefile.

P.S. Just as a side note, there is a small issue in your code: you should open Core.Std not Core.

like image 60
ivg Avatar answered Oct 13 '22 04:10

ivg