X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FExceptions.hs;h=c1fec6f0d83057ee71dbcb81845e10b6f6aa9678;hb=98d03792f46f3ac870c010a78944822569e76763;hp=dd31ea3cc155d879ba5366966b04e9b4ca5a4808;hpb=d126623dc6895d325e3d204d74e2a22d4f515587;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test/Exceptions.hs b/src/Language/Haskell/LSP/Test/Exceptions.hs index dd31ea3..c1fec6f 100644 --- a/src/Language/Haskell/LSP/Test/Exceptions.hs +++ b/src/Language/Haskell/LSP/Test/Exceptions.hs @@ -1,7 +1,6 @@ module Language.Haskell.LSP.Test.Exceptions where import Control.Exception -import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Types import Data.Aeson import Data.Aeson.Encode.Pretty @@ -11,25 +10,30 @@ import Data.List import qualified Data.ByteString.Lazy.Char8 as B -- | An exception that can be thrown during a 'Haskell.LSP.Test.Session.Session' -data SessionException = Timeout +data SessionException = Timeout (Maybe FromServerMessage) | NoContentLengthHeader | UnexpectedMessage String FromServerMessage | ReplayOutOfOrder FromServerMessage [FromServerMessage] | UnexpectedDiagnostics | IncorrectApplyEditRequest String - | UnexpectedResponseError LspIdRsp ResponseError + | UnexpectedResponseError SomeLspId ResponseError | UnexpectedServerTermination + | IllegalInitSequenceMessage FromServerMessage deriving Eq instance Exception SessionException instance Show SessionException where - show Timeout = "Timed out waiting to receive a message from the server." + show (Timeout lastMsg) = + "Timed out waiting to receive a message from the server." ++ + case lastMsg of + Just msg -> "\nLast message received:\n" ++ B.unpack (encodePretty msg) + Nothing -> mempty show NoContentLengthHeader = "Couldn't read Content-Length header from the server." show (UnexpectedMessage expected lastMsg) = "Received an unexpected message from the server:\n" ++ "Was parsing: " ++ expected ++ "\n" ++ - "Last message received: " ++ show lastMsg + "Last message received:\n" ++ B.unpack (encodePretty lastMsg) show (ReplayOutOfOrder received expected) = let expected' = nub expected getJsonDiff = lines . B.unpack . encodePretty @@ -46,6 +50,9 @@ instance Show SessionException where show (UnexpectedResponseError lid e) = "Received an exepected error in a response for id " ++ show lid ++ ":\n" ++ show e show UnexpectedServerTermination = "Language server unexpectedly terminated" + show (IllegalInitSequenceMessage msg) = + "Received an illegal message between the initialize request and response:\n" + ++ B.unpack (encodePretty msg) -- | A predicate that matches on any 'SessionException' anySessionException :: SessionException -> Bool