X-Git-Url: http://git.lukelau.me/?p=lsp-test.git;a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FParsing.hs;h=2936b31347f9db69ecf4b1a3951c552336953cfb;hp=36349dae864f4fbd63aa82c6016d87da1bd52084;hb=7ee14165e9d2ebcc171716d41e3e207444c418b3;hpb=e0926c045ccd5444f3112cb231cc3590c600d48d diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index 36349da..2936b31 100644 --- a/src/Language/Haskell/LSP/Test/Parsing.hs +++ b/src/Language/Haskell/LSP/Test/Parsing.hs @@ -10,6 +10,7 @@ import Control.Lens import Control.Monad.IO.Class import Control.Monad import Data.Aeson +import Data.Aeson.Encode.Pretty import qualified Data.ByteString.Lazy.Char8 as B import Data.Conduit.Parser import Data.Maybe @@ -42,9 +43,10 @@ satisfy pred = do if pred x then do - liftIO $ do - setSGR [SetColor Foreground Vivid Magenta] - putStrLn $ "<-- " ++ B.unpack (encodeMsg x) + shouldLog <- asks $ logMessages . config + liftIO $ when shouldLog $ do + setSGR [SetColor Foreground Dull Magenta] + putStrLn $ "<-- " ++ B.unpack (encodeMsgPretty x) setSGR [Reset] return x else empty @@ -86,6 +88,9 @@ castMsg = fromMaybe (error "Failed casting a message") . decode . encodeMsg encodeMsg :: FromServerMessage -> B.ByteString encodeMsg = encode . genericToJSON (defaultOptions { sumEncoding = UntaggedValue }) +encodeMsgPretty :: FromServerMessage -> B.ByteString +encodeMsgPretty = encodePretty . genericToJSON (defaultOptions { sumEncoding = UntaggedValue }) + -- | Matches if the message is a log message notification or a show message notification/request. loggingNotification :: Session FromServerMessage loggingNotification = named "Logging notification" $ satisfy shouldSkip