lsp-test

Functional test framework for LSP servers. https://github.com/bubba/lsp-test#readme

Version on this page:0.10.1.0
LTS Haskell 15.7:0.10.2.0
Stackage Nightly 2020-04-10:0.10.2.0
Latest on Hackage:0.10.2.0

See all snapshots lsp-test appears in

BSD-3-Clause licensed by Luke Lau
Maintained by [email protected]

Module documentation for 0.10.1.0

This version can be pinned in stack with:[email protected]:4aeb4a23a6e034f6870a2ca6055029061cdb6b68f833d4314f4f839fe6c8a39c,3472

lsp-test Actions Status Hackage

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

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

Examples

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 test. For more examples check the Wiki

Developing

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

haskell-ide-engine

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

javascript-typescript-langserver

npm i -g javascript-typescript-langserver

Then run the tests with cabal test or stack test.

Troubleshooting

Seeing funny stuff when running lsp-test via stack? If your server is built upon Haskell tooling, keep in mind that stack sets some environment variables related to GHC, and you may want to unset them.

Changes

Revision history for lsp-test

0.10.1.0 – 2019-02-04

  • Bump constraints for new haskell-lsp

0.10.0.0 – 2019-12-29

  • Account for messages received between the initialize request and response. (Though it will throw an exception if the message received is an illegal one)

0.9.0.0 – 2019-12-1

  • Add ignoreLogNotifications config option
  • Add ability to override logStdErr and logMessages config options with the LSP_TEST_LOG_STDERR and LOG_TEST_LOG_MESSAGES environment variables
  • Update for haskell-lsp-0.19.0.0 (@mpickering)

0.8.2.0 – 2019-11-17

  • Expose satisfyMaybe (@cocreature)

0.8.1.0 – 2019-11-17

  • Update to haskell-lsp-0.18.0.0 (@mpickering, @alanz)
  • Tests now require hie-bios based hie

0.8.0.0 – 2019-10-18

  • Make Session a newtype
  • Update for haskell-lsp-0.17.0.0 (@cocreature)

0.7.0.0 – 2019-09-08

  • Update for haskell-lsp-0.16.0.0

0.6.1.0 – 2019-08-24

  • Add satisfyMaybe (@cocreature)

0.6.0.0 – 2019-07-04

  • Update to haskell-lsp-0.15.0.0 (@lorenzo)

0.5.4.0 – 2019-06-13

  • Fix getDefinitions for SingleLoc (@cocreature)
  • Add getCodeLenses (@cocreature)

0.5.3.0 – 2019-06-13

  • Update to haskell-lsp-0.14.0.0 (@cocreature)
  • Support TextDocumentDidChange (@cocreature)
  • Add non-file based openDoc (@cocreature)

0.5.2.0 – 2019-04-28

  • Add satisfy parser combinator

0.5.1.0 – 2019-04-22

  • Fix unhandled window/progress server notifications

0.5.1.0 – 2019-04-07

  • Add getTypeDefinitions (@fendor)

0.5.0.2 – 2018-12-05

  • Fix loose threads when exceptions are thrown

0.5.0.0 – 2018-11-13

  • Add lspConfig option in config
  • GHC 8.6.2 support

0.4.0.0 – 2018-09-08

  • Update to haskell-lsp-0.8.0.0

0.3.0.0 – 2018-09-0t

  • Update to haskell-lsp-0.7.0.0

0.2.1.0 – 2018-08-14

  • Add getCodeActions
  • Add getCurrentDiagnostics

0.2.0.0 – 2018-08-06

  • Update to haskell-lsp 0.6.0.0