-whenRequest :: B.ByteString -> (LSP.RequestMessage Value Value Value -> IO ()) -> IO ()
-whenRequest msg = forM_ (decode msg :: (Maybe (LSP.RequestMessage Value Value Value)))
+ response :: LSP.ResponseMessage Value -> Session [B.ByteString]
+ response res = do
+ lift $ putStrLn $ "Got response for id " ++ show (res ^. LSP.id)
+
+ lift $ print res
+
+ checkOrder res
+
+ lift $ putMVar reqSema (res ^. LSP.id) -- unblock the handler waiting to send a request
+
+ return $ deleteFirstJson res expectedMsgs
+
+ request :: LSP.RequestMessage LSP.ServerMethod Value Value -> Session [B.ByteString]
+ request req = do
+ lift $ putStrLn $ "Got request for id " ++ show (req ^. LSP.id) ++ " " ++ show (req ^. LSP.method)
+
+ lift $ print req
+
+ checkOrder req
+
+ lift $ putMVar rspSema (req ^. LSP.id) -- unblock the handler waiting for a response
+
+ return $ deleteFirstJson req expectedMsgs
+
+ notification :: LSP.NotificationMessage LSP.ServerMethod Value -> Session [B.ByteString]
+ notification n = do
+ lift $ putStrLn $ "Got notification " ++ show (n ^. LSP.method)
+ lift $ print n
+ return $ deleteFirstJson n expectedMsgs
+
+ checkOrder msg = unless (inRightOrder msg expectedMsgs) $ do
+ let expected = decode firstExpected
+ _ = expected == Just msg -- make expected type same as res
+ failSession ("Out of order\nExpected\n" ++ show expected ++ "\nGot\n" ++ show msg ++ "\n")
+
+
+isNotification :: B.ByteString -> Bool
+isNotification msg =
+ isJust (decode msg :: Maybe (LSP.NotificationMessage Value Value))