Add lspConfig option
[opengl.git] / src / Language / Haskell / LSP / Test / Session.hs
index 5948ed0a818c1aed1b28cbef5b5f463d1b952ce7..f0d410afed37c295a9ebdac061471056f1bb882b 100644 (file)
@@ -2,6 +2,7 @@
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE RankNTypes #-}
 
 module Language.Haskell.LSP.Test.Session
   ( Session
@@ -30,6 +31,7 @@ import Control.Concurrent hiding (yield)
 import Control.Exception
 import Control.Lens hiding (List)
 import Control.Monad
+import Control.Monad.Fail
 import Control.Monad.IO.Class
 import Control.Monad.Except
 import Control.Monad.Trans.Reader (ReaderT, runReaderT)
@@ -69,17 +71,23 @@ import System.IO
 
 type Session = ParserStateReader FromServerMessage SessionState SessionContext IO
 
+instance MonadFail Session where
+  fail s = do
+    lastMsg <- fromJust . lastReceivedMessage <$> get
+    liftIO $ throw (UnexpectedMessage s lastMsg)
+
 -- | Stuff you can configure for a 'Session'.
 data SessionConfig = SessionConfig
   { messageTimeout :: Int  -- ^ Maximum time to wait for a message in seconds, defaults to 60.
   , logStdErr      :: Bool -- ^ Redirect the server's stderr to this stdout, defaults to False.
   , logMessages    :: Bool -- ^ Trace the messages sent and received to stdout, defaults to True.
   , logColor       :: Bool -- ^ Add ANSI color to the logged messages, defaults to True.
+  , lspConfig      :: Maybe Value -- ^ The initial LSP config as JSON value, defaults to Nothing.
   }
 
 -- | The configuration used in 'Language.Haskell.LSP.Test.runSession'.
 defaultConfig :: SessionConfig
-defaultConfig = SessionConfig 60 False False True
+defaultConfig = SessionConfig 60 False True True Nothing
 
 instance Default SessionConfig where
   def = defaultConfig