Stack(age) and HLS workflow(s)?

So far, I’ve used Stack (and Stackage) with decent success in my Haskell projects. But I’ve been hitting some walls, and I’m curious if I’m missing something.

Recently, I tried to upgrade my Stackage LTS and hit some issues. That linked thread talks about the missing ormolu package, but in this thread I’d like to discuss my HLS issues :smiley:

TL;DR: HLS (installed via ghcup) 2.14.0.0 breaks with the latest Stackage LTS (GHC 9.10.3). It works out-of-the-box with the GHC 9.8 and 9.6 LTSs, though. It seems to be an ABI mismatch, maybe? I’m not sure if this is a bug or expected behavior.

Doing some research I’ve found that: “In general, HLS needs to be compiled with the exact same compiler you used to compile your project.” The solutions seem to be: set Stack to use system GHC or compile HLS with your exact stack GHC.

Okay, but: Stack allows me to isolate projects and GHC versions, which is what I want. How can I work on multiple projects, each of which uses a different GHC version? Do I need to compile a separate HLS for every project? Does ghcup let me do that easily? Or… what are my other options? Juggle different GHC versions in ghcup and switch them around manually, set stack to use “system” GHC?

I guess what I’m confused about here is: I’m using what I thought was a pretty common setup: stack + stackage LTS + HLS. But, like… for example, if I stack new, the default project doesn’t even work with HLS. I get a bunch of “expected Cabal-xxx…” errors in the logs.

How do people manage these issues in their own projects? Am I doing something crazy? :sweat_smile:

I personally just don’t use hls lol

In GHCUp, you can see in the list of compilers which ones are “HLS-powered”. I run HLS 2.15, and I can see that GHC 9.10.3 is “HLS-powered”. That’s a good start.

Then, make sure that stack is using the GHC that’s installed through GHCUp, not some other one. I can’t recall how that’s configured, but if you install stack via GHCUp, it should already be the case.

Finally, in case HLS doesn’t detect your configuration for some reason, you can also add a hie.yaml file at the root of your project to tell HLS about your build tool.

So, to recap:

  • Install everything through GHCUp : ghc, stack, and hls
  • Use the right HLS version; 2.14 probably works, just check through GHCUp with ghcup tui
  • In case the above fails, set up a hie.yaml

~/.stack/config.yaml

system-ghc: true
install-ghc: false

overrides project level config if there is any (which usually there isn’t when it comes to this)

Regarding this: any given version of HLS supports many versions of GHC. It’s not strictly true that HLS only supports the exact compiler version that compiled it.

For example, HLS 2.15 supports:

  • GHC 9.14.1
  • GHC 9.12.4
  • GHC.9.10.3
  • GHC 9.8.4
  • GHC 9.6.7

That’s not a bad list!