haskell / haskell-mode

Emacs mode for Haskell
http://haskell.github.io/haskell-mode/
GNU General Public License v3.0
1.33k stars 342 forks source link

haskell-process-get-repl-completions completely hangs Emacs if REPL is inside IO action #1332

Open cobalamin opened 8 years ago

cobalamin commented 8 years ago

I noticed this by using company-mode with the company-ghc backend. It's an easy way to reproduce this problem.

I have a hook to enable company-mode inside haskell-interactive-mode. It works great usually, but recently I've noticed that my entire Emacs sometimes freezes up. After some investigation, I noticed that this happens only when I'm inside an IO action and either waiting (company-mode by default triggers after a certain amount of time) or triggering the completion manually. A simple getLine is enough, but a forever $ putStrLn ... loop also works.

I don't think company-mode nor company-ghc are to blame here, since they seem to simply use haskell-process-get-repl-completions. I killed my GHC process and had a look at the log:

-> getLine
<- ghc: signal: 15

-> :complete repl "\nasd"
<- 0 0 "\n"

<- ghc: signal: 15
ghc: signal: 15

<- Leaving GHCi.
Leaving GHCi.

Event: "finished
"

Process reset.

(everything after ghc: signal 15 happens when I call kill <ghc-process-id> twice)

I noticed that this :complete repl ... call always occurs before REPL+Emacs start hanging. So I looked in my .emacs.d for files which send such a command, and haskell-process.el in haskell-mode showed up, specifically the haskell-process-get-repl-completions. And sure enough, when I insert a (debug) statement at the top of the function, I can see that this function is called when my problem would occur, and Emacs doesn't start hanging since it's not executing the rest.

This is possibly in some way related to https://github.com/haskell/haskell-mode/issues/871. However, I'm not in multiline mode. To make sure, I explicitly executed :unset +m before doing the same thing, and the problem still occurred.

Further info:

geraldus commented 8 years ago

Haskell mode uses singe REPL process for all tasks now. Hence, when you try to get completions while REPL is busy Emacs hangs. Same happens when REPL is in multiline mode (completion function hangs Emacs). So, basically REPL can handle only single action at a time. We discussed this issue few times, but no decision was made. The most terrible thing is that Haskell mode have Interactive mode and Inferior mode. I believe both of them serve for same purposes and must be merged into one non-blocking REPL backend. However they differ in details a bit and there is a lot of work to make things right. Personally I have no enough power right now to make any contributions.

fice-t commented 8 years ago

@geraldus Would using haskell-process-evaluating-p work in this case, at least to stop the hanging?

geraldus commented 8 years ago

@fice-t I don't know. Somebody have to test this.

fice-t commented 8 years ago

I tested it and it does detect it fine. Wrapping haskell-process-get-repl-completions in (if (haskell-process-evaluating-p process) nil ... seems to work. If it returned a special symbol (say 'evaluating) would that help the completion functions?

Eason0210 commented 3 years ago

Is there any workaround to make haskell-interactive-mode work with company-mode? I tried to use run this main function on haskell-interactive-mode, and it will hangs Emacs when I input every char . Forturnitly, C-g can make it restored to normal.

main = do
  input <- getLine
  putStrLn input
lastgosumatt commented 2 years ago

@Eason0210 same here, did you find any solution?

Eason0210 commented 2 years ago

@lastgosumatt The issue still exist. I use terminal to run such kind of code instead.

Eason0210 commented 2 years ago

I tried to use corfu (a new completion front end) instead of company, It works well in haskell-interactive-mode.

Any one have some suggestions to fixed it, and make company work with haskell-interactive-mode?

idhowardgj94 commented 1 year ago

same here, so the problem is company mode plu haskell-interactive-mode?

idhowardgj94 commented 1 year ago

confirm that, work well if I close company mode.