Add getInitializeResponse
authorLuke Lau <luke_lau@icloud.com>
Tue, 12 Jun 2018 21:55:49 +0000 (17:55 -0400)
committerLuke Lau <luke_lau@icloud.com>
Tue, 12 Jun 2018 21:55:49 +0000 (17:55 -0400)
src/Language/Haskell/LSP/Test.hs
src/Language/Haskell/LSP/Test/Parsing.hs

index 17a39c5a9702a9e2146514c65165220270ff516f..8da0cbbee8ba065533e8e0d06ac79e3f35ee4612 100644 (file)
@@ -54,6 +54,7 @@ module Language.Haskell.LSP.Test
   , (<|>)
   , satisfy
   -- * Utilities
+  , getInitializeResponse
   , openDoc
   , getDocItem
   , getDocUri
@@ -100,8 +101,13 @@ runSession serverExe rootDir session = do
 
     -- Wrap the session around initialize and shutdown calls
     sendRequest Initialize initializeParams
-    initRsp <- response :: Session InitializeResponse
-    liftIO $ maybe (return ()) (putStrLn . ("Error while initializing: " ++) . show ) (initRsp ^. LSP.error)
+    initRspMsg <- response :: Session InitializeResponse
+
+    liftIO $ maybe (return ()) (putStrLn . ("Error while initializing: " ++) . show ) (initRspMsg ^. LSP.error)
+
+    initRspVar <- initRsp <$> ask
+    liftIO $ putMVar initRspVar initRspMsg
+    
 
     sendNotification Initialized InitializedParams
 
@@ -129,8 +135,9 @@ runSessionWithHandler serverHandler serverExe rootDir session = do
   reqMap <- newMVar newRequestMap
   messageChan <- newChan
   meaninglessChan <- newChan
+  initRsp <- newEmptyMVar
 
-  let context = SessionContext serverIn absRootDir messageChan reqMap
+  let context = SessionContext serverIn absRootDir messageChan reqMap initRsp
       initState = SessionState (IdInt 9)
 
   threadId <- forkIO $ void $ runSession' meaninglessChan context initState (serverHandler serverOut)
@@ -224,6 +231,12 @@ sendMessage msg = do
   h <- serverIn <$> ask
   liftIO $ B.hPut h $ addHeader (encode msg)
 
+-- | Returns the initialize response that was received from the server.
+-- The initialize requests and responses are not included the session,
+-- so if you need to test it use this.
+getInitializeResponse :: Session InitializeResponse
+getInitializeResponse = initRsp <$> ask >>= (liftIO . readMVar)
+
 -- | Opens a text document and sends a notification to the client.
 openDoc :: FilePath -> String -> Session TextDocumentIdentifier
 openDoc file languageId = do
index 3496322ca6ff0f8d95bd799fb23ffc219484c04e..8c05590304533b59e95dc1400875f9a20ad8cb87 100644 (file)
@@ -27,7 +27,8 @@ data SessionContext = SessionContext
     serverIn :: Handle,
     rootDir :: FilePath,
     messageChan :: Chan FromServerMessage,
-    requestMap :: MVar RequestMap
+    requestMap :: MVar RequestMap,
+    initRsp :: MVar InitializeResponse
   }
 
 newtype SessionState = SessionState