X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FExceptions.hs;h=b28e256cc0857522c4558dd2d38e3823b6b3efbf;hb=84e2707604b3a64c00062104fa40e2ea76040155;hp=88cf57d11ed6910391856ed85ffe9b244fcc5e26;hpb=16501021ea92ae3c84dbfd99a3c2dd631685b49c;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test/Exceptions.hs b/src/Language/Haskell/LSP/Test/Exceptions.hs index 88cf57d..b28e256 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 @@ -17,8 +16,9 @@ data SessionException = Timeout (Maybe FromServerMessage) | ReplayOutOfOrder FromServerMessage [FromServerMessage] | UnexpectedDiagnostics | IncorrectApplyEditRequest String - | UnexpectedResponseError LspIdRsp ResponseError + | UnexpectedResponseError SomeLspId ResponseError | UnexpectedServerTermination + | IllegalInitSequenceMessage FromServerMessage deriving Eq instance Exception SessionException @@ -27,13 +27,13 @@ instance Show SessionException where show (Timeout lastMsg) = "Timed out waiting to receive a message from the server." ++ case lastMsg of - Just msg -> "\nLast message received: " ++ show msg + 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 + "But the last message received was:\n" ++ B.unpack (encodePretty lastMsg) show (ReplayOutOfOrder received expected) = let expected' = nub expected getJsonDiff = lines . B.unpack . encodePretty @@ -50,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