fix: Add temporary workaround for Intero + GHC 8.4 bug

Adds a workaround for commercialhaskell/intero#569 by adding a
function that disables the offending GHCi flag in the Intero REPL, and
advising the `intero-repl` and `intero-repl-load` commands to always
execute it.

I did not manage to locate a common entrypoint to the REPL, but it's
probably not worth spending more time on as this will be fixed
properly in a future GHC release.
This commit is contained in:
Vincent Ambo 2018-09-12 11:21:19 +02:00 committed by Vincent Ambo
parent 0cf7af4403
commit bab9f15a33

View file

@ -231,4 +231,32 @@ Including indent-buffer, which should not be called automatically on save."
(inferior-erlang
(format "nix-shell --command erl %s" (cdr (project-current)))))
(defun intero-fix-ghci-panic ()
"Disable deferring of out of scope variable errors, which
triggers a bug in the interactive Emacs REPL printing a panic
under certain conditions."
(interactive)
(let* ((root (intero-project-root))
(package-name (intero-package-name))
(backend-buffer (intero-buffer 'backend))
(name (format "*intero:%s:%s:repl*"
(file-name-nondirectory root)
package-name))
(setting ":set -fno-defer-out-of-scope-variables\n"))
(when (get-buffer name)
(with-current-buffer (get-buffer name)
(goto-char (point-max))
(let ((process (get-buffer-process (current-buffer))))
(when process (process-send-string process setting)))))))
;; Brute-force fix: Ensure the setting is injected every time the REPL
;; is selected.
;;
;; Upstream issue: https://github.com/commercialhaskell/intero/issues/569
(advice-add 'intero-repl :before (lambda (&rest r) (intero-fix-ghci-panic))
'((name . intero-panic-fix)))
(advice-add 'intero-repl-load :before (lambda (&rest r) (intero-fix-ghci-panic))
'((name . intero-panic-fix)))
(provide 'functions)