a Haskell Development Environment consist in a compiler (ghc
), a language server (hls
), a building tool (cabal
or stack
), and an editor compatible with the language server protocol.
The best way to have a coherent installation of these components is with the ghcup tool.
- Step 1: Install GHCup. You'll be prompted to install some tools. Say yes to
hls
. Do not installstack
yet (see below). - Step 2: Install vscode
- Step 3: Open vscode and install the haskell extension either using the extension panel or pressing CTRL+P and
ext install haskell.haskell
.
If you want an editor different from vscode, check the documentation here
to integrate stack
with haskell-language-server
, you should configure it properly.
The key point is to prevent stack
to install ghc
on its own. Follow these steps:
-
First, You still need to follow the three steps at the top of this guide. You can't get a proper working environment solely with
stack
. -
Skip this point if you installed
stack
independently fromghcup
. In a terminal runghcup install stack
-
Configure
stack
to use system'sghc
. Configuration can be either global (recomended) or local- Global (recomended)
# Run on a terminal if you want to set a global configuration stack config set install-ghc --global false stack config set system-ghc --global true
- Local:
# On stack.yaml add this line if you want to set a local configuration system-ghc: true
- Global (recomended)
-
You must use a
stack
snapshot compatible with theghc
version installed byghcup
. Visit stackage to get theghc
version on each sanpshot. For examplelts-18.28
usesghc-8.10.7
. You can check version compatibility with:# This prints the ghc's version installed by ghcup > ghcup list -c installed -t ghc ✔✔ ghc 8.10.7 recommended,base-4.14.3.0 hls-powered # Your resolver should point to 18.28 --------------------------------------------------- > cat stack.yaml # vvvvv resolver: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml
In case you need to use a different snapshot you have to install it's ghc
version with ghcup
. For the sake of example, let say you are using lts-16.31
, which uses ghc-8.8.4
. Then you need to run ghcup install ghc 8.8.4
on a terminal. Also, depending on which snapshot you are using, you might loose integration with hls
. Check hls
documentation for more info.
This isn't a bug. It is the expected behaviour, but poorly documented in my opinion.
up to the hls release page
Meaning that if you use
stack
to installghc
thenhls
won't be able to work (and if it does, It is just luck). Moreover, I've being able to reproduce this and get a very strange error. Also, notice that this is fixed in the most recent release ofstack
but I haven't updated the guideAlso this same configuration is refered in the
stack
guide:https://docs.haskellstack.org/en/stable/Stack_and_VS_Code/#workaround-1