First, we have to setup lsp-mode. Then, we will setup haskell-mode that provides syntax highlighting for Haskell source files, and lsp-haskell for LSP services.

haskell-mode setup

I prefer module management. So I create a file lisp/haskell.el, and write

1
2
3
4
5
6
7
8
9
(use-package haskell-mode
:ensure t
:mode ("\\.hs\\'" "\\.lhs\\'")) ; provide syntax highight

;; Add hooks to lsp
(add-hook 'haskell-mode-hook #'lsp)
(add-hook 'haskell-literate-mode-hook #'lsp)

(provide 'haskell)

lsp-mode setup

Also, lsp-haskell is not pre-configured by lsp-mode. That means we should manually setup executable file for hls. In lisp/lsp.el (where I put my use-package lsp-mode), add

1
2
:custom
(lsp-haskell-server-path "/home/lunatic/.ghcup/bin/haskell-language-server-wrapper")

lsp-haskell setup

Then in init.el, we have to manually enable lsp-haskell, lsp-mode and haskell-mode. Note that, since our haskell.el uses add-hook, so it should be evaluated after lsp-mode.

1
2
3
(require 'lsp)
(require 'lsp-haskell)
(require 'haskell)

And that’s it!