haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

Managing different versions of GHC #3209

Closed Nifrec closed 1 year ago

Nifrec commented 2 years ago

Your environment

Which OS do you use? Manjaro Linux (Mostly identical to Arch Linux, can also use AUR packages).

Which version of GHC do you use and how did you install it?

How is your project built (alternative: link to the project)? Via the stack tool. It uses the resolver lts-16.13.

Which LSP client (editor/plugin) do you use? Vim with CoC.

Which version of HLS do you use and how did you install it? The version from the Manjaro repositories (see below in Debug information).

Have you configured HLS in any way (especially: a hie.yaml file)? No I have not.

What's wrong?

So far I have used Manjaro's Haskell packages (including GHC and HLS), and match well with my text editor. However, for a university project I needed to install stack and use a snapshot using an older version of the GHC. Stack installed the older version of GHC, and in this directory it indeed uses this older version correctly. Somehow, also my text editor gets routed to using this older GHC, but it still uses the system HLS. This version of HLS is incompatible with the project. But I do not know how to install the different versions of HLS side-by-side?

Error in Vim:

ghcide compiled against GHC 9.0.2 but currently using 8.8.4                    
This is unsupported, ghcide must be compiled with the same GHC version as the  
project. (cradle)  

Tried

I have tried to install the older version of HLS from source: $stack install --stack-yaml stack-lts16.yaml. This does make my text editor work within the university project, but now, of course, it breaks in projects using the newer HLS version:

ghcide compiled against GHC 8.8.4 but currently using 9.0.2                                                                          
This is unsupported, ghcide must be compiled with the same GHC version as the                                                        
project. (cradle) 

If I launch Vim instead with a modified PATH that excludes the stack directory (~/.local.bin), then everything also works for projects using GHC 9.0.2.

This is rather cumbersome though, and it gets much more complicated as soon as I need to work with 3 versions of GHC. Is there perhaps a more elegant solution?

Debug information

Official HLS packages from the Manjaro repository:

$ pacman --quiet -Qs hls                                                                                                
local/haskell-hls-call-hierarchy-plugin 1.0.1.0-39
    Call hierarchy plugin for Haskell Language Server
local/haskell-hls-eval-plugin 1.1.2.0-244
    Eval plugin for Haskell Language Server
local/haskell-hls-explicit-imports-plugin 1.0.1.0-239
    Explicit imports plugin for Haskell Language Server
local/haskell-hls-floskell-plugin 1.0.0.2-23
    Integration with the Floskell code formatter
local/haskell-hls-fourmolu-plugin 1.0.0.2-249
    Integration with the Fourmolu code formatter
local/haskell-hls-graph 1.4.0.0-191
    Haskell Language Server internal graph API
local/haskell-hls-haddock-comments-plugin 1.0.0.4-9
    Haddock comments plugin for Haskell Language Server
local/haskell-hls-hlint-plugin 1.0.1.1-239
    Hlint integration plugin with Haskell Language Server
local/haskell-hls-module-name-plugin 1.0.0.3-8
    Module name plugin for Haskell Language Server
local/haskell-hls-ormolu-plugin 1.0.1.0-247
    Integration with the Ormolu code formatter
local/haskell-hls-plugin-api 1.2.0.1-34
    Haskell Language Server API for plugin communication
local/haskell-hls-pragmas-plugin 1.0.1.1-37
    Pragmas plugin for Haskell Language Server
local/haskell-hls-retrie-plugin 1.0.1.2-24
    Retrie integration plugin for Haskell Language Server
local/haskell-hls-stylish-haskell-plugin 1.0.0.2-242
    Integration with the Stylish Haskell code formatter

System Haskell version:

$ ghc --version                                                                                            
The Glorious Glasgow Haskell Compilation System, version 9.0.2

Stack Haskell version (inside project):

$ stack exec -- ghc --version    
The Glorious Glasgow Haskell Compilation System, version 8.8.4

Outside the project directory stack also uses 9.0.2.

michaelpj commented 1 year ago

We suggest using ghcup to manage your GHCs. Otherwise this sounds like a Manjaro packaging problem.

langfield commented 1 year ago

It should be mentioned that ghcup integrates quite nicely with stack, see here.

Nifrec commented 1 year ago

Sorry for the late response, only finally got time to get around to try it (was expecting a lot of issues). Installed ghcup, it works smoothly out of the box and installed the right versions automatically. Also my text editor found compatible language servers in the different projects, so the issue is solved! 🙂