haskell-mode
haskell-mode copied to clipboard
haskell-process-get-repl-completions completely hangs Emacs if REPL is inside IO action
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:
-
stack ghc -- --version
:The Glorious Glasgow Haskell Compilation System, version 7.10.3
- haskell-mode 20160518.945
-
M-x version
:GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2015-04-10 on builder10-9.porkrind.org
-
M-x eval-expression haskell-process-type
:stack-ghci
-
stack --version
:Version 1.0.4 x86_64
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.
@geraldus Would using haskell-process-evaluating-p
work in this case, at least to stop the hanging?
@fice-t I don't know. Somebody have to test this.
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?
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
@Eason0210 same here, did you find any solution?
@lastgosumatt The issue still exist. I use terminal to run such kind of code instead.
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
?
same here, so the problem is company mode plu haskell-interactive-mode?
confirm that, work well if I close company mode.