Emacs/haskell flycheck and HLS/lsp - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Magnus Therning

Another question regarding settting up a nice Haskell environment in Emacs.

Since intero was abandoned I've been using HLS and lsp-haskell (via Spacemacs). It's working really well, but there's one slightly strange behaviour I've obeserved regarding syntax checking with flycheck.

The lsp checker doesn't warn on a few things that I like to have warnings on, e.g. imports of unused modules, so I have configured a chain like this:

(add-hook 'haskell-mode-hook
          (lambda ()
            (lsp)
            (flycheck-add-next-checker 'lsp '(warning . haskell-ghc))))

That almost works like I want, in order to get errors from all checkers in the first file I open I have to either

  • apply a hint, or
  • force a save of the file, or
  • I evaluate (flycheck-start-current-syntax-check 'lsp), or
  • open a second file and then jump back to the first again

I tried adding (flycheck-start-current-syntax-check 'lsp) to the hook (after setting the next checker), but that made no difference.

I must be doing something wrong!
There's clearly some timing issue, but what can I do to fix it?
Am I even putting the chain setup on a good hook?

Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs, intended as replacement for the older Flymake extension which is part of GNU Emacs. For a detailed comparison to Flymake see Flycheck versus Flymake.
Peter J. Jones

I use eglot instead of the lsp package because I find it to be a bit more sane. With HLS it works out of the box for warnings, errors, and hints. The only downside is that it uses flymake instead of flycheck.

A client for Language Server Protocol servers. Contribute to joaotavora/eglot development by creating an account on GitHub.
Peter J. Jones

This is my Emacs + Haskell setup: https://github.com/pjones/emacsrc/blob/trunk/modes/haskell-mode-conf.el

My Emacs configuration files. Contribute to pjones/emacsrc development by creating an account on GitHub.
Magnus Therning

I guess my search continues...

Magnus Therning

After quite a bit of trial and error I managed to find something that works: https://magnus.therning.org/posts/2021-03-05-000-flycheck-and-hls.html

Suggestions and improvements are always welcome, of course!