From: Luke Lau Date: Fri, 29 Jun 2018 00:40:57 +0000 (+0100) Subject: Log session messages, don't know why it was ever a good idea to hide them 💩 X-Git-Tag: 0.1.0.0~49 X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=commitdiff_plain;h=563d0885c5cf4456ea04c041771d68dca5c274d4 Log session messages, don't know why it was ever a good idea to hide them 💩 --- diff --git a/haskell-lsp-test.cabal b/haskell-lsp-test.cabal index 510b758..4683c60 100644 --- a/haskell-lsp-test.cabal +++ b/haskell-lsp-test.cabal @@ -22,6 +22,7 @@ library , haskell-lsp-types , haskell-lsp >= 0.3 , aeson + , ansi-terminal , async , bytestring , conduit diff --git a/src/Language/Haskell/LSP/Test.hs b/src/Language/Haskell/LSP/Test.hs index 1ce6871..0e8f5bf 100644 --- a/src/Language/Haskell/LSP/Test.hs +++ b/src/Language/Haskell/LSP/Test.hs @@ -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, diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index fdc2e95..db5e443 100644 --- a/src/Language/Haskell/LSP/Test/Parsing.hs +++ b/src/Language/Haskell/LSP/Test/Parsing.hs @@ -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