X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FParsing.hs;h=12ef1a6281547c4fc73dd4ad812cb71c529e95f5;hb=af401b6d0439751d73ea230a219f37eb57286c90;hp=0810d20c0f56f45909ef5b3d30c79b78c34019de;hpb=1294a1fbb1578d87cc1fb4c10bc5f91e54cf9904;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index 0810d20..12ef1a6 100644 --- a/src/Language/Haskell/LSP/Test/Parsing.hs +++ b/src/Language/Haskell/LSP/Test/Parsing.hs @@ -6,6 +6,7 @@ module Language.Haskell.LSP.Test.Parsing ( -- $receiving satisfy + , satisfyMaybe , message , anyRequest , anyResponse @@ -23,7 +24,8 @@ import Control.Monad.IO.Class import Control.Monad import Data.Aeson import qualified Data.ByteString.Lazy.Char8 as B -import Data.Conduit.Parser +import Data.Conduit.Parser hiding (named) +import qualified Data.Conduit.Parser (named) import qualified Data.Text as T import Data.Typeable import Language.Haskell.LSP.Messages @@ -68,12 +70,12 @@ satisfy pred = satisfyMaybe (\msg -> if pred msg then Just msg else Nothing) -- | Consumes and returns the result of the specified predicate if it returns `Just`. -- --- @since 0.5.3.0 +-- @since 0.6.1.0 satisfyMaybe :: (FromServerMessage -> Maybe a) -> Session a satisfyMaybe pred = do skipTimeout <- overridingTimeout <$> get - timeoutId <- curTimeoutId <$> get + timeoutId <- getCurTimeoutId unless skipTimeout $ do chan <- asks messageChan timeout <- asks (messageTimeout . config) @@ -81,10 +83,9 @@ satisfyMaybe pred = do threadDelay (timeout * 1000000) writeChan chan (TimeoutMessage timeoutId) - x <- await + x <- Session await - unless skipTimeout $ - modify $ \s -> s { curTimeoutId = timeoutId + 1 } + unless skipTimeout (bumpTimeoutId timeoutId) modify $ \s -> s { lastReceivedMessage = Just x } @@ -94,6 +95,9 @@ satisfyMaybe pred = do return a Nothing -> empty +named :: T.Text -> Session a -> Session a +named s (Session x) = Session (Data.Conduit.Parser.named s x) + -- | Matches a message of type @a@. message :: forall a. (Typeable a, FromJSON a) => Session a message =