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

Introduction

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

What is this?

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)

How to use

import Language.Haskell.LSP.Test
import Language.Haskell.LSP.Types
main = 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.

Sending and receiving manually

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

Combinators

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))

My server's not written in Haskell

Check out the guide for setting up a minimal Haskell environment for running tests

Clone this wiki locally