# Revision history for lsp-test
+## 0.5.2.0 -- 2019-04-28
+
+* Add `satisfy` parser combinator
+
## 0.5.1.0 -- 2019-04-22
* Fix unhandled `window/progress` server notifications
name: lsp-test
-version: 0.5.1.4
+version: 0.5.2.0
synopsis: Functional test framework for LSP servers.
description:
A test framework for writing tests against
matches d = d ^. source == Just (T.pack src)
-- | Expects a 'PublishDiagnosticsNotification' and throws an
--- 'UnexpectedDiagnosticsException' if there are any diagnostics
+-- 'UnexpectedDiagnostics' exception if there are any diagnostics
-- returned.
noDiagnostics :: Session ()
noDiagnostics = do
module Language.Haskell.LSP.Test.Parsing
( -- $receiving
- message
+ satisfy
+ , message
, anyRequest
, anyResponse
, anyNotification
-- anyResponse
-- @
+-- | Consumes and returns the next message, if it satisfies the specified predicate.
+--
+-- @since 0.5.2.0
satisfy :: (FromServerMessage -> Bool) -> Session FromServerMessage
satisfy pred = do
return x
else empty
--- | Matches a message of type 'a'.
+-- | Matches a message of type @a@.
message :: forall a. (Typeable a, FromJSON a) => Session a
message =
let parser = decode . encodeMsg :: FromServerMessage -> Maybe a
-- | A session representing one instance of launching and connecting to a server.
--
--- You can send and receive messages to the server within 'Session' via 'getMessage',
--- 'sendRequest' and 'sendNotification'.
---
+-- You can send and receive messages to the server within 'Session' via
+-- 'Language.Haskell.LSP.Test.message',
+-- 'Language.Haskell.LSP.Test.sendRequest' and
+-- 'Language.Haskell.LSP.Test.sendNotification'.
type Session = ParserStateReader FromServerMessage SessionState SessionContext IO
logMsg LogClient msg
liftIO $ B.hPut h (addHeader $ encode msg)
--- | Execute a block f that will throw a 'TimeoutException'
+-- | Execute a block f that will throw a 'Timeout' exception
-- after duration seconds. This will override the global timeout
-- for waiting for messages to arrive defined in 'SessionConfig'.
withTimeout :: Int -> Session a -> Session a
documentContents doc >>= liftIO . print
in sesh `shouldThrow` anyException
+ describe "satisfy" $
+ it "works" $ runSession "hie" fullCaps "test/data" $ do
+ openDoc "Format.hs" "haskell"
+ let pred (NotLogMessage _) = True
+ pred _ = False
+ void $ satisfy pred
+
mkRange sl sc el ec = Range (Position sl sc) (Position el ec)
didChangeCaps :: ClientCapabilities