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

Issues with auto-complete and company support in merlin when used with flycheck-ocaml #404

Closed drvink closed 9 years ago

drvink commented 9 years ago

It's not clear if this is a merlin bug or a flycheck-ocaml bug (flycheck/flycheck-ocaml#3), so I'm filing an issue here in the hope the root cause can be found.

flycheck-ocaml breaks if company-mode or auto-complete-mode (or both) are enabled. Strange parts of the buffer will get highlighted as errors; in particular, messages like these are common:

Merlin was already processing ((tell start at ((assoc) (line . 35) (col . 31)))) while ((tell start at ((assoc) (line . 35) (col . 31)))) was attempted

With auto-completion-mode specifically, Emacs will lock up after showing a completion listing.

I'm seeing this on Emacs 24.5.1 with the latest flycheck, merlin, company, and auto-complete.

let-def commented 9 years ago

Merlin doesn't expects to synchronous commands to happen concurrently (in this case, completion and error-checking), we had a lot of difficulty to find a convenient api for emacs, the situation is still not satisfying.

I think error-checking could be made to use the asynchronous interface. Who is maintaining the flycheck integration of merlin? The fix shouldn't take long, but I am not a flycheck user so I won't be able to test.

drvink commented 9 years ago

I have no familiarity at all with merlin's guts, but I'm willing to offer any help I can in tracking down the issue and testing changes.

let-def commented 9 years ago

@lunaryorn updated flycheck-ocaml code. Could you test on your side? I am not 100% confident about my code ;).

let-def commented 9 years ago

@drvink I have patched versions of merlin.el and flycheck-ocaml.el, could you try with those files in your local installation and tell if that fixes the bug?

let-def commented 9 years ago

See here https://gist.github.com/def-lkb/d3cc4907b81f15cc26d7

drvink commented 9 years ago

OK, let me give it a try.

drvink commented 9 years ago

Backtrace with the new files

JFYI, I had to change the version requirement for flycheck-ocaml.el to use merlin 1.4 to prevent package-install-from-buffer from fetching the ELPA one (since the version number of merlin.el in your gist is 1.4)

let-def commented 9 years ago

Wow! You are using completion-at-point, not the merlin-company-backend.

let-def commented 9 years ago

Look at https://github.com/the-lambda-church/merlin/wiki/emacs-from-scratch#company-mode for the setup.

drvink commented 9 years ago

Oh dear. Let me try that and get back to you.

let-def commented 9 years ago

NP, it might fail as well, but if that's the case it will be easier to debug this way :)

drvink commented 9 years ago

Backtrace with the correct config :)

Sorry about that!

let-def commented 9 years ago

Ok, something went wrong with the version of merlin.el I shared. Some parts of the code look 6 months old?!, its like I mixed different version of the same file. Sorry for the inconvenience, I'll try to fix that.

let-def commented 9 years ago

This version of the gist looks saner https://gist.github.com/def-lkb/d3cc4907b81f15cc26d7

drvink commented 9 years ago

Backtrace using those files

let-def commented 9 years ago

@drvink: do you have some kind of instant messager (or IRC) so that we can have more interactive discussion? That would help solving this quickly

drvink commented 9 years ago

IRC would work; where should I connect?

let-def commented 9 years ago

On freenode, I am def`, you can also find me on #ocaml.

let-def commented 9 years ago

This issue should be fixed. Feel free to reopen/comment if you still have problems.

drvink commented 9 years ago

Seems like there are still some issues--Emacs will occasionally lock up. auto-complete-mode is fine, but company-mode isn't. Furthermore, there are frequent pauses if I stop typing momentarily and then start again. flycheck also gets desynchronized from the buffer--I'll get nonsensical error messages (like it claiming something is a string when it's an int).

drvink commented 9 years ago

I spoke too soon--I get a very occasional hard lockup even with company-mode off and only auto-complete-mode and flycheck-mode on. @def-lkb Let me know if there's any way I can provide more information.

let-def commented 9 years ago

Where you able to produce a stack trace of those lockups?

drvink commented 9 years ago

@def-lkb I'll try to get something from within Emacs when the lockup happens, but if I can't, I can get Emacs to dump core, and you might be able to do something with that, since Emacs includes gdb scripts which will give a complete stack trace (including the calls into Lisp from C and vice versa).