1 module Language.Haskell.LSP.Test.Exceptions where
3 import Control.Exception
4 import Language.Haskell.LSP.Messages
5 import Language.Haskell.LSP.Types
7 import qualified Data.ByteString.Lazy.Char8 as B
9 data SessionException = TimeoutException
10 | UnexpectedMessageException String FromServerMessage
11 | ReplayOutOfOrderException FromServerMessage [FromServerMessage]
12 | UnexpectedDiagnosticsException
13 | IncorrectApplyEditRequestException String
14 | UnexpectedResponseError LspIdRsp ResponseError
16 instance Exception SessionException
18 instance Show SessionException where
19 show TimeoutException = "Timed out waiting to receive a message from the server."
20 show (UnexpectedMessageException expected lastMsg) =
21 "Received an unexpected message from the server:\n" ++
22 "Expected: " ++ expected ++ "\n" ++
23 "Last message accepted: " ++ show lastMsg
24 show (ReplayOutOfOrderException received expected) =
25 "Replay is out of order:\n" ++
26 -- Print json so its a bit easier to update the session logs
27 "Received from server:\n" ++ B.unpack (encode received) ++ "\n" ++
28 "Expected one of:\n" ++ unlines (map (B.unpack . encode) expected)
29 show UnexpectedDiagnosticsException = "Unexpectedly received diagnostics from the server."
30 show (IncorrectApplyEditRequestException msgStr) = "ApplyEditRequest didn't contain document, instead received:\n"
32 show (UnexpectedResponseError lid e) = "Received an exepected error in a response for id " ++ show lid ++ ":\n"
35 anySessionException :: SessionException -> Bool
36 anySessionException = const True