Add notice that this was merged into haskell/lsp
[lsp-test.git] / README.md
1 # lsp-test [![Actions Status](https://github.com/bubba/lsp-test/workflows/Haskell%20CI/badge.svg)](https://github.com/bubba/lsp-test/actions) [![Hackage](https://img.shields.io/hackage/v/lsp-test.svg)](https://hackage.haskell.org/package/lsp-test)
2 lsp-test is a functional testing framework for Language Server Protocol servers.
3
4 ```haskell
5 import Language.Haskell.LSP.Test
6 main = runSession "hie" fullCaps "proj/dir" $ do
7   doc <- openDoc "Foo.hs" "haskell"
8   skipMany anyNotification
9   symbols <- getDocumentSymbols doc
10 ```
11
12 ## Examples
13
14 ### Unit tests with HSpec
15 ```haskell
16 describe "diagnostics" $
17   it "report errors" $ runSession "hie" fullCaps "test/data" $ do
18     openDoc "Error.hs" "haskell"
19     [diag] <- waitForDiagnosticsSource "ghcmod"
20     liftIO $ do
21       diag ^. severity `shouldBe` Just DsError
22       diag ^. source `shouldBe` Just "ghcmod"
23 ```
24
25 ### Replaying captured session
26 ```haskell
27 replaySession "hie" "test/data/renamePass"
28 ```
29
30 ### Parsing with combinators
31 ```haskell
32 skipManyTill loggingNotification publishDiagnosticsNotification
33 count 4 (message :: Session ApplyWorkspaceEditRequest)
34 anyRequest <|> anyResponse
35 ```
36
37 Try out the example tests in the `example` directory with `cabal test`.
38 For more examples check the [Wiki](https://github.com/bubba/lsp-test/wiki/Introduction), or see this [introductory blog post](https://lukelau.me/haskell/posts/lsp-test/).
39
40 Whilst writing your tests you may want to debug them to see what's going wrong.
41 You can set the `logMessages` and `logStdErr` options in `SessionConfig` to see what the server is up to.
42 There are also corresponding environment variables so you can turn them on from the command line:
43 ```
44 LSP_TEST_LOG_MESSAGES=1 LSP_TEST_LOG_STDERR=1 cabal test
45 ```
46
47 ## Developing
48 The tests for lsp-test use a dummy server found in `test/dummy-server/`.
49 Run the tests with `cabal test` or `stack test`.
50 Tip: If you want to filter the tests, use `cabal run test:tests -- -m "foo"`
51
52 ## Troubleshooting
53 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.](https://github.com/alanz/haskell-ide-engine/blob/bfb16324d396da71000ef81d51acbebbdaa854ab/test/utils/TestUtils.hs#L290-L298)