How to setup GHCup + Emacs Haskell LSP

Цей допис українською!

Haskell provides a tremendous language server. However, I had some hard minutes fixing Emacs issues with a path to collection of Haskell related binaries installed by GHCup.

Hope this post will help you to avoid them.

Install GHCup

Pretty straightforward step, just run an installation command from GHCup site:

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Of course, opt in to install haskell-language-server since you need it according to this article.

Wait. Long.

Add Haskell packages to init.el

I use use-package (and encourage you do the same), hence I install packages in such manner:

;;; init.el
(use-package haskell-mode) ; install mode for Haskell files
(use-package lsp-mode) ; you will definitely need LSP support
(use-package lsp-ui) ; that's a nice LSP package as well
;; finally, Haskell LSP setup:
(use-package lsp-haskell
  :hook
  (haskell-mode . lsp)
  (haskell-literate-mode . lsp))

My init.el in case you need more context.

Teach Emacs where GHCup binaries reside

Two simple lines:

(setenv "PATH" (concat (getenv "PATH") ":" (expand-file-name "~/.ghcup/bin")))
(setq exec-path (append exec-path '(expand-file-name "~/.ghcup/bin")))

Just put them into init.el and you are done.

Nevertheless, I sweated a lot before figuring out that tilda alias (~) works with expand-file-name command only.