How to make Merlin (OCaml) ignore some lines?

426 Views Asked by At

I use Merlin with Emacs to edit OCaml code. It normally works perfectly fine, but I wound the following problem:

I'm need to use a package, built by someone else, that adds to OCaml some keywords not native to the language. Since I use the package to compile the code, compilation works great. On the other hand Merlin goes crazy and thinks that the new keywords are an error. Luckily the new keywords only appear at the beginning of a line, so my code looks something like this:

let square x = x * x;;

let rec fact x =
    if x <= 1 then 1 else x * fact (x - 1);;

FOO "This syntax is not standard Ocaml" square fact;;

Where FOO is the new keyword. Merlin will complain and say Unbound constructor FOO. So the question is, can I make Marlin ignore that line? OR can you think of a hack to wrap the syntax in something Merlin won't complain about?

2

There are 2 best solutions below

0
On BEST ANSWER

Merlin doesn't and will not (afaik) support arbitrary syntax extensions, but they do have parsing hacks for most commonly used camlp4 extensions like pa_lwt, pa_macro, etc. Also newest merlin versions will skip unknown lines and recover parsing, so that 'go-to-definition' and type throwback work on other parts of the file not modified by syntax extensions.

0
On

An alternative, although quite different, but that offers a subset of the functionalities of Merlin (completion and documentation from libraries, navigating around files), is ocp-index.

Ocp-index doesn't interpret or type your current file (it only scans it for opens and the like), so it won't be troubled by arbitrary extensions.