+-- | An internal version of 'runSession' that allows for a custom handler to listen to the server.
+-- It also does not automatically send initialize and exit messages.
+runSessionWithHandler :: (Handle -> Session ())
+ -> String
+ -> FilePath
+ -> Session a
+ -> IO a
+runSessionWithHandler serverHandler serverExe rootDir session = do
+ absRootDir <- canonicalizePath rootDir
+
+ let createProc = (shell serverExe) { std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
+ (Just serverIn, Just serverOut, _, serverProc) <- createProcess createProc
+
+ hSetBuffering serverIn NoBuffering
+ hSetBuffering serverOut NoBuffering
+
+ reqMap <- newMVar newRequestMap
+ messageChan <- newChan
+ meaninglessChan <- newChan
+ initRsp <- newEmptyMVar
+
+ let context = SessionContext serverIn absRootDir messageChan reqMap initRsp
+ initState = SessionState (IdInt 9)
+
+ threadId <- forkIO $ void $ runSession' meaninglessChan context initState (serverHandler serverOut)
+ (result, _) <- runSession' messageChan context initState session