ocaml / merlin

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

Better ppx error reporting #514

Open qoocku opened 8 years ago

qoocku commented 8 years ago

Like this:

"""
Merlin failed with error: "Error: Error while running external preprocessor
Command line: ppx_lwt '/tmp/camlppxcb0ddf' '/tmp/camlppx12a59f' 1>/dev/null 2>/dev/null
"""

It auto-completes something anyway but using only words textually gathered from buffers which does not make me happy at all. ppx_lwt exists and is runnable, of course. Ocaml version: 4.02.3 installed using OPAM

let-def commented 8 years ago

Do you still have the problem?

A few questions to help understanding the problem:

SGrondin commented 7 years ago

Hi, I'm experiencing the same error.

I'm trying to get it to work with Sublime Text 3 using https://github.com/cynddl/sublime-text-merlin/. Everything was fine until I tried to use lwt.ppx. The code compiles correctly when I use let%lwt, it's just Merlin that's having issues.

I can reproduce the problem with this minimal test.ml:

open Lwt

let some_func str = Lwt_io.printl str

(* Main *)
let _ =
  Lwt_unix.run (some_func "hi!")

Here's the .merlin for the test:

S src

B _build/src
B +threads
PKG ppx_let
PKG lwt
PKG lwt.ppx
PKG lwt.unix

And the Sublime Text 3 error (Look at the last line):

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 231, in run_callback
    expr()
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 288, in <lambda>
    run_callback('on_post_save', callback, lambda: callback.on_post_save(v))
  File "/Users/simon/Library/Application Support/Sublime Text 3/Packages/Merlin/merlin/helpers.py", line 48, in wrapper
    return func(self, view, *args, **kwargs)
  File "/Users/simon/Library/Application Support/Sublime Text 3/Packages/Merlin/sublime-text-merlin.py", line 463, in on_post_save
    merlin_view(view).sync()
  File "/Users/simon/Library/Application Support/Sublime Text 3/Packages/Merlin/merlin/process.py", line 194, in sync
    return self.send_query("tell", "start", "end", text)
  File "/Users/simon/Library/Application Support/Sublime Text 3/Packages/Merlin/merlin/process.py", line 153, in send_query
    return self.process.send_command(command)
  File "/Users/simon/Library/Application Support/Sublime Text 3/Packages/Merlin/merlin/process.py", line 132, in send_command
    raise Error(content)
Merlin.merlin.process.Error: {'sub': [], 'type': 'type', 'valid': True, 'message': "Error: Error while running external preprocessor\nCommand line: ppx_lwt '/var/folders/mj/thk903fx5gxbk32vy5n_5yfm0000gn/T/camlppxaf0cb4' '/var/folders/mj/thk903fx5gxbk32vy5n_5yfm0000gn/T/camlppx7bdd07' 1>/dev/null\n"}

Due to that last line, I then tried to run ppx_lwt directly like this: ppx_let src/test.ml test.txt

This is the resulting error: Failure("Ast_mapper: OCaml version mismatch or malformed input")

Thank you

trefis commented 7 years ago

The reporting of errors related to ppx is indeed terrible at the moment, we hope to make it better in the near future.

SGrondin commented 7 years ago

Indeed, the error reporting could be better. Is there any way for me to find the source of the problem so I can make lwt.ppx work with Merlin at this time?

trefis commented 7 years ago

The error means that merlin and lwt.ppx don't agree on the version of OCaml you are using. Make sure that both executables come from the same opam switch and you should be good.

SGrondin commented 7 years ago

Thanks @trefis . I don't want to turn this issue into a personal debugging session, but I'll report the current state I'm in for the next people finding this issue through Google or Github searches.

I indeed found 2 (!) system ocaml installations (both through brew). They didn't seem to be used, so I removed them. I now only have the 4.02.3 switch through OPAM, but I'm still getting the exact errors as before.

simon@errmac:~/Documents/ocaml/test$ which ocamlmerlin
/Users/simon/.opam/4.02.3/bin/ocamlmerlin
simon@errmac:~/Documents/ocaml/test$ which ocaml
/Users/simon/.opam/4.02.3/bin/ocaml
simon@errmac:~/Documents/ocaml/test$ which ppx_lwt
/Users/simon/.opam/4.02.3/bin/ppx_lwt

I'll add info to this post if I make progress on this.

let-def commented 7 years ago

The problem seems to be different, it seems to me that merlin cannot find ppx_lwt. Under OSX, the session often doesn't have OPAM setup in environment. This is done only when starting a login shell. Since I assume you used the launcher to start sublime text which subsequently started merlin, merlin doesn't know about OPAM setup. If you can start sublime text from a terminal, that could help in understanding. If it works in this case, the fix is probably to use a login shell to start ocamlmerlin from sublime text.

The Failure("Ast_mapper: OCaml version mismatch or malformed input") is expected: you are manually running a ppx preprocessor on a source file. Preprocessors only accept marshalled ast.

Merlin produce a dump of this ast in case of failure, in your case it was /var/folders/mj/thk903fx5gxbk32vy5n_5yfm0000gn/T/camlppx.lastfail. Check the exit code of ppx_let /var/.../camlppx.lastfail test.ast.