Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Setting up Haskell

Luke Lau edited this page Dec 29, 2019 · 3 revisions

Installing

You'll need GHC, a Haskell compiler, and cabal-install, the package manager:

Travis CI

addons:
  apt:
    packages:
    - ghc
    - cabal-install

Apt

sudo apt install ghc cabal-install

Homebrew

brew install ghc cabal-install

After they're installed be sure to run

cabal update

Test-suite setup

mkdir tests
cd tests

Create a file called tests.cabal

name: tests
version: 0.1.0.0
build-type: Simple
cabal-version: 2.0

test-suite tests
  type:          exitcode-stdio-1.0
  main-is:       Test.hs
  build-depends: base
               , lsp-test

And inside Test.hs

import Language.Haskell.LSP.Test
main = runSession "my-server" fullCaps "." $
  liftIO $ putStrLn "Hello world"

To run your tests, inside the tests directory call

cabal test

And lsp-test should now be running your server!

With HSpec

For a more batteries-included testing setup with Hspec, we recommend the following dependencies

test-suite tests
  type:          exitcode-stdio-1.0
  main-is:       Test.hs
  build-depends: base
               , lsp-test
               , hspec

And a Test.hs like

import Language.Haskell.LSP.Test
import Language.Haskell.LSP.Types
import Test.Hspec
main = hspec $ do
  describe "my feature" $ do
    it "does this" $ runSession ...
    it "does that" $ runSession ...
  describe "my other feature" $ do
    it "works" $ runSession ...
    it "works when" $ runSession ...
Clone this wiki locally