-response :: Monad m => ConduitParser FromServerMessage m FromServerMessage
-response = satisfy isServerResponse
+anyResponse :: Session FromServerMessage
+anyResponse = named "Any response" $ satisfy isServerResponse
+
+-- | Matches a response for a specific id.
+responseForId :: forall a. FromJSON a => LspId -> Session (ResponseMessage a)
+responseForId lid = named (T.pack $ "Response for id: " ++ show lid) $ do
+ let parser = decode . encodeMsg :: FromServerMessage -> Maybe (ResponseMessage a)
+ x <- satisfy (maybe False (\z -> z ^. LSP.id == responseId lid) . parser)
+ return $ castMsg x
+
+-- | Matches any type of message.
+anyMessage :: Session FromServerMessage
+anyMessage = satisfy (const True)
+
+-- | A stupid method for getting out the inner message.
+castMsg :: FromJSON a => FromServerMessage -> a
+castMsg = fromMaybe (error "Failed casting a message") . decode . encodeMsg
+
+-- | A version of encode that encodes FromServerMessages as if they
+-- weren't wrapped.
+encodeMsg :: FromServerMessage -> B.ByteString
+encodeMsg = encode . genericToJSON (defaultOptions { sumEncoding = UntaggedValue })