ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.58k stars 233 forks source link

Merlin can fail to error-check correctly if a build fails before dependent cmi's generated #302

Closed mcclure closed 9 years ago

mcclure commented 9 years ago

My situation: I have a project containing a src/main.ml, which depends on a src/execute.ml, which depends on a src/value.ml and src/token.ml. (https://bitbucket.org/runhello/emily , if it matters or you want to see my Makefile or .merlin.) I have merlin 2.0.0 installed via opam and vim 7.4 +python installed via MacPorts. When I want to build, a makefile runs ocamlbuild -no-links -use-ocamlfind src/main.native. If there are errors, I check them by opening the file containing the error in vi and typing :w, triggering Merlin.

This is a situation I am seeing right this instant. There is a syntax error in execute.ml. I do these steps:

It appears that since execute.ml failed early with a syntax error, ocamlbuild did not attempt to build execute.ml's dependent cmis; and that merlin/vi then just died because it doesn't build things, it only loads previously made cmis.

I feel like I shouldn't have had to go through this rigamarole of running ocamlbuild twice by hand. Imagine if my project had had six or seven dependencies instead of just two...? And "when there is an error" is a poor time for an error-reporting feature to stop working. Should this be happening? Is it fixable?

let-def commented 9 years ago

The problem you have is that your build system is unable to work on syntactically incorrect files. Merlin works later in the workflow, having a working build system is a requirement. But you're right that this case is a weak spot.

The blocking point here is dependency computation. Luckily, it is possible to approximate dependency computations in this case (as shown by merlin, which is able to ask for Value and Token modules, so dependencies are known at this point). It is just not implemented in the existing build systems which where not made for handling incorrect input.

(providing an alternative ocamldep shouldn't take long)

let-def commented 9 years ago

This patch to ocamldep should do it https://gist.github.com/def-lkb/9f7ba3b2bfd7cf845408 (untested). If should be possible to get this upstreamed.

gasche commented 9 years ago

@def-lkb if/when we manage to upstream some work on error resilience and reporting for the OCaml compiler, it should be easy to adapt ocamldep to also work on the "correctly parsed" part of a parser state.

gasche commented 9 years ago

(Hadn't seen your patch. Yes, this sounds like a reasonable heuristic. Could you send a GPR or mantis PR about this?)

let-def commented 9 years ago

(yes)