This repository has been archived by the owner on Mar 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Introduction
Luke Lau edited this page Jul 31, 2018
·
8 revisions
It's a framework that lets you control a mock LSP client to talk to your server. Use it to make integration tests for your server's functionality. (You could probably also use it to make an actual client too)
import Haskell.LSP.Test
import Haskell.LSP.Types
runSession "hie" fullCaps "my/project" $ do
doc <- openDoc "Bar.hs" "haskell"
loggingNotification -- assert we receive a logging type message
diags <- getDefinitions doc (Position 4 5)
rename doc (Position 2 3) "howdy"
documentContents doc >>= liftIO . print
Tests are contained within a Session
, a complete connection between your server and the test client from the initialise request to the exit notification.
There are a bunch of built in functions for doing common actions, such as opening a document or asserting that you receive a message. These all use Haskell.LSP.Types, which you probably want to import as well.
HSpec is also useful if you want to use it to write unit tests.
runSession "hie" fullCaps "my/dir" = do
doc <- openDoc "Foo.hs" "haskell"
let params = DocumentSymbolParams doc
-- send and wait for the response
rsp <- sendRequest TextDocumentDocumentSymbol params
-- or manually send and wait
sendRequest' TextDocumentSymbol params
-- next immediate message must be a DocumentSymbolsResponse
message :: Session DocumentSymbolsResponse
let closeParams = DidCloseTextDocumentParams doc
sendNotification TextDocumentDidClose closeParams
Session
is actually a parser under the hood, so you can use all your favourite combinators:
nEdits :: Session [ApplyWorkspaceEditRequest]
nEdits = skipManyTill anyResponse (count n (message :: Session ApplyWorkspaceEditRequest))