25db5848dd07f444f97644e59e0518f6dcf988c9
[opengl.git] / src / Language / Haskell / LSP / Test / Exceptions.hs
1 module Language.Haskell.LSP.Test.Exceptions where
2
3 import Control.Exception
4 import Language.Haskell.LSP.Messages
5
6 data SessionException = TimeoutException
7                       | UnexpectedMessageException String FromServerMessage
8                       | ReplayOutOfOrderException FromServerMessage [FromServerMessage]
9                       | UnexpectedDiagnosticsException
10                       | IncorrectApplyEditRequestException String
11
12 instance Exception SessionException
13
14 instance Show SessionException where
15   show TimeoutException = "Timed out waiting to receive a message from the server."
16   show (UnexpectedMessageException expected lastMsg) =
17     "Received an unexpected message from the server:\n" ++
18     "Expected: " ++ expected ++ "\n" ++
19     "Last message accepted: " ++ show lastMsg
20   show (ReplayOutOfOrderException received expected) =
21     "Replay is out of order:\n" ++
22     "Received from server:" ++ show received ++ "\n" ++
23     "Expected one of: " ++ concatMap show expected
24   show UnexpectedDiagnosticsException = "Unexpectedly received diagnostics from the server."
25   show (IncorrectApplyEditRequestException msgStr) = "ApplyEditRequest didn't contain document, instead received:\n"
26                                           ++ msgStr
27
28 anySessionException :: SessionException -> Bool
29 anySessionException = const True