Haskell language server tries to use incorrect GHC version

244 Views Asked by At

I'm trying to use Haskell language server in Spacemacs. I installed HLS using ghcup. My operating system is Ubuntu 20.04.5. When opening a hs-file in Spacemacs, I get the following error message:

No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.5.0.0 x86_64 ghc-9.2.8
Current directory: ~/Documents/Code/hs-nexus-parser
Operating system: linux
Arguments: ["--lsp","-d","-l","/tmp/hls.log"]
Cradle directory: ~/Documents/Code/hs-nexus-parser
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.10.2.1
stack:          2.13.1
ghc:            8.6.5


Consulting the cradle to get project GHC version...
2024-02-02T15:20:42.278912Z | Debug | executing command: stack setup --silent
2024-02-02T15:20:42.574191Z | Debug | executing command: stack exec ghc -- --numeric-version
Project GHC version: 9.6.4
haskell-language-server exe candidates: ["haskell-language-server-9.6.4","haskell-language-server"]
Failed to find a HLS version for GHC 9.6.4
Executable names we failed to find: haskell-language-server-9.6.4,haskell-language-server
 2024-02-02T15:20:42.927797Z | Info | Starting server
2024-02-02T15:20:42.929304Z | Error | Got error while decoding initialize:
Error in $.params.capabilities.window.showMessage: parsing ShowMessageRequestClientCapabilities failed, expected Object, but encountered Null

Process lsp-haskell stderr finished

It appears to me that there are several problems occurring at the same time.

Firstly, HLS appears to find the wrong GHC version in $PATH. I made sure to prepend ~/.ghcup/bin to PATH. The ghc version in this directory is 9.4.8 which should work together with the hls version I have installed. I also checked the directories in PATH and cannot find a ghc 8.6.5 version. When I run ghc --version in a terminal it gives me version 9.4.8.

Secondly, when the GHC version that it finds does not match HLS appears to fall back to the GHC version in the local stack project. To prevent this I added system-ghc: true to the local stack.yaml file yet that does not seem to help.

As far as I understand, Stack should be integrated with ghcup as I installed it together with ghcup with standard settings. To make sure that this works I uninstalled a previous stack version by deleting ~/.stack.

Expected behaviour: HLS uses some GHC that is compatible with it for code completion.

1

There are 1 best solutions below

0
On

I had basically this issue with a custom Emacs set up. I went looking in ~/.ghcup/bin and I had nothing for haskell-language-server-9.6.4 or haskell-language-server, so how I got around it was installing hls 2.6.0.0, even though it's currently latest rather than recommended.

I ran:

$ ghcup install hls 2.6.0.0

And Emacs worked like a charm. No need to set it to default or anything.

I feel like something is still funky with the fact that hls is ignoring the config files and looking for ghc 9.6.4, so I get this answer isn't totally satisfying, but this got LSP running well enough for my purposes. Hope this helps!