Log session messages, don't know why it was ever a good idea to hide them 💩
authorLuke Lau <luke_lau@icloud.com>
Fri, 29 Jun 2018 00:40:57 +0000 (01:40 +0100)
committerLuke Lau <luke_lau@icloud.com>
Fri, 29 Jun 2018 00:40:57 +0000 (01:40 +0100)
haskell-lsp-test.cabal
src/Language/Haskell/LSP/Test.hs
src/Language/Haskell/LSP/Test/Messages.hs
src/Language/Haskell/LSP/Test/Parsing.hs

index 510b7583a128835fcf04903b017846ff24f8a697..4683c6061f13b1adb655110eef92cef2fcd959d4 100644 (file)
@@ -22,6 +22,7 @@ library
                      , haskell-lsp-types
                      , haskell-lsp >= 0.3
                      , aeson
+                     , ansi-terminal
                      , async
                      , bytestring
                      , conduit
index 1ce6871fb211f3a66e75f7ac95d65bbb979a4085..0e8f5bfcaa92259f253defa2d89bbb40610c1e66 100644 (file)
@@ -93,6 +93,7 @@ import Language.Haskell.LSP.Test.Exceptions
 import Language.Haskell.LSP.Test.Parsing
 import Language.Haskell.LSP.Test.Session
 import Language.Haskell.LSP.Test.Server
+import System.Console.ANSI
 import System.IO
 import System.Directory
 import System.FilePath
@@ -273,7 +274,16 @@ sendResponse = sendMessage
 sendMessage :: ToJSON a => a -> Session ()
 sendMessage msg = do
   h <- serverIn <$> ask
-  liftIO $ B.hPut h $ addHeader (encode msg)
+  let encoded = encode msg
+  liftIO $ do
+
+    setSGR [SetColor Foreground Vivid Cyan]
+    putStrLn $ "--> " ++ B.unpack encoded
+    setSGR [Reset]
+
+    B.hPut h (addHeader encoded)
+
+
 
 -- | Returns the initialize response that was received from the server.
 -- The initialize requests and responses are not included the session,
index fdc2e958bafc45eae1e02deceba80ba4e03657b4..db5e4433b582dde899d7b0ae908eb1fa52b4a850 100644 (file)
@@ -17,8 +17,9 @@ import Language.Haskell.LSP.Types hiding (error)
 import Language.Haskell.LSP.Test.Exceptions
 import Language.Haskell.LSP.Test.Messages
 import Language.Haskell.LSP.Test.Session
+import System.Console.ANSI
 
-satisfy :: (MonadIO m, MonadSessionConfig m) => (a -> Bool) -> ConduitParser a m a
+satisfy :: (MonadIO m, MonadSessionConfig m) => (FromServerMessage -> Bool) -> ConduitParser FromServerMessage m FromServerMessage
 satisfy pred = do
   timeout <- timeout <$> lift sessionConfig
   tId <- liftIO myThreadId
@@ -27,6 +28,12 @@ satisfy pred = do
     throwTo tId TimeoutException
   x <- await
   liftIO $ killThread timeoutThread
+
+  liftIO $ do
+    setSGR [SetColor Foreground Vivid Magenta]
+    putStrLn $ "<-- " ++ B.unpack (encodeMsg x)
+    setSGR [Reset]
+
   if pred x
     then return x
     else empty