Functional test framework for LSP servers.

Version on this page:
LTS Haskell 22.25:
Stackage Nightly 2024-06-13:
Latest on Hackage:

See all snapshots lsp-test appears in

BSD-3-Clause licensed by Luke Lau
Maintained by [email protected]
This version can be pinned in stack with:lsp-test-,3483

Module documentation for

lsp-test Build Status Hackage

lsp-test is a functional testing framework for Language Server Protocol servers.

import Language.Haskell.LSP.Test
runSession "hie" fullCaps "proj/dir" $ do
  doc <- openDoc "Foo.hs" "haskell"
  skipMany anyNotification
  symbols <- getDocumentSymbols doc


Unit tests with HSpec

describe "diagnostics" $
  it "report errors" $ runSession "hie" fullCaps "test/data" $ do
    openDoc "Error.hs" "haskell"
    [diag] <- waitForDiagnosticsSource "ghcmod"
    liftIO $ do
      diag ^. severity `shouldBe` Just DsError
      diag ^. source `shouldBe` Just "ghcmod"

Replaying captured session

replaySession "hie" "test/data/renamePass"

Parsing with combinators

skipManyTill loggingNotification publishDiagnosticsNotification
count 4 (message :: Session ApplyWorkspaceEditRequest)
anyRequest <|> anyResponse

Try out the example tests in the example directory with cabal new-test. For more examples check the Wiki


The tests are integration tests, so make sure you have the following language servers installed and on your PATH:


  • Check out a relatively recent version of the repo, or see .travis.yml to get the exact commit used for CI.
  • stack install


npm i -g javascript-typescript-langserver

Then run the tests with stack test or cabal new-test.


Revision history for lsp-test – 2019-08-24

  • Add satisfyMaybe (@cocreature) – 2019-07-04

  • Update to haskell-lsp- (@lorenzo) – 2019-06-13

  • Fix getDefinitions for SingleLoc (@cocreature)
  • Add getCodeLenses (@cocreature) – 2019-06-13

  • Update to haskell-lsp- (@cocreature)
  • Support TextDocumentDidChange (@cocreature)
  • Add non-file based openDoc (@cocreature) – 2019-04-28

  • Add satisfy parser combinator – 2019-04-22

  • Fix unhandled window/progress server notifications – 2019-04-07

  • Add getTypeDefinitions (@fendor) – 2018-12-05

  • Fix loose threads when exceptions are thrown – 2018-11-13

  • Add lspConfig option in config
  • GHC 8.6.2 support – 2018-09-08

  • Update to haskell-lsp- – 2018-09-0t

  • Update to haskell-lsp- – 2018-08-14

  • Add getCodeActions
  • Add getCurrentDiagnostics – 2018-08-06

  • Update to haskell-lsp