Prerequisites for IDE Editors
Credits
- https://github.com/tmphey
- @nymeron#8182
In order to setup your favorite editor for Haskell/Plutus development you need following components - GHC (haskell compiler) & cabal (build system for haskell projects) - haskell-language-server
GHC & cabal
You have 2 options for setting up the compiler infrastructure:
- Using Nix and nix-shell. Assuming you've done setup of plutus for running plutus-playground
locally, you already have ghc
and cabal
binaries available inside nix-shell
.
- System-wide installation. Generally, if you don't want to run plutus-playground
locally and only want to compile Plutus contracts, you can use your existing haskell installation or install the compiler toolchain without Nix. For using this method, follow the instructions on ghcup website.
HSL (haskell-language-server)
IDE-like features like auto-completion, type hints, docs and jump-to-definition are provided by a tool called haskell-language-server. It is a standalone program that implements Language Server Protocol (LSP) for Haskell. Your editor can talk to this program and get the information for showing types, doing auto-completion, etc.
Linux
On Linux, installing the HSL is pretty straightforwad. If you've done Nix setup then you already have haskell-language-server
binary on your $PATH
inside nix-shell
.
If you've done installation with ghcup
, you can install HSL with following command
$PATH
.
macOS
On macOS, the installation is a bit trickier. Due to linking proglems HSL crashes when your project uses TemplateHaskell (which Plutus uses a lot) (issue, issue). The workaround for this is to compile HSL manually with dynamic linking support.
- Make sure you have ghc & cabal installed and available on your
$PATH
(either locally or withinnix-shell
) - Clone HSL repo
- Make changes to
haskell-language-server.cabal
file to use dynamic linking (huge shoutout to@nymeron#8182
for finding that). The diff - Find out your ghc version
- Build HSL for your compiler version
- Once the build is done, newly created binary will be located in
$HOME/.cabal/bin
. If you usenix-shell
, make sure that you use right binary since nix-shell provides its own.
Once you have everything set up you can proceed to configuring your editor.