From a4180c432755f683d07605f4413135d6cfadc065 Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Tue, 12 Jun 2018 17:55:49 -0400 Subject: [PATCH] Add getInitializeResponse --- src/Language/Haskell/LSP/Test.hs | 19 ++++++++++++++++--- src/Language/Haskell/LSP/Test/Parsing.hs | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 17a39c5..8da0cbb 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -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 diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index 3496322..8c05590 100644 --- a/src/Language/Haskell/LSP/Test/Parsing.hs +++ b/src/Language/Haskell/LSP/Test/Parsing.hs @@ -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 -- 2.30.2