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 installstackyet (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
stackindependently fromghcup. In a terminal runghcup install stack -
Configure
stackto 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
stacksnapshot compatible with theghcversion installed byghcup. Visit stackage to get theghcversion on each sanpshot. For examplelts-18.28usesghc-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.
Saying no to GHCup HLS (yes to everything else), and then letting the Haskell extension install HLS seems to work fine. Either GHCup or the extension, I don't know which one, creates a stack hook to prevent it from installing its own GHC. There's no further need to mess with stack anyway.
https://www.haskell.org/ghcup/guide/#strategy-1-stack-hooks-new-recommended
Debugging and testing (HSpec) still don't work from VSCode though. The debug adapter extension is $shit.