X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FParsing.hs;h=2936b31347f9db69ecf4b1a3951c552336953cfb;hb=7ee14165e9d2ebcc171716d41e3e207444c418b3;hp=1b76e867b580ec8d15e3df74ea69234306adc955;hpb=a4c1143848809be8aed55403dc3187a256dcbe9b;p=opengl.git diff --git a/src/Language/Haskell/LSP/Test/Parsing.hs b/src/Language/Haskell/LSP/Test/Parsing.hs index 1b76e86..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 @@ -53,9 +55,8 @@ satisfy pred = do message :: forall a. (Typeable a, FromJSON a) => Session a message = let parser = decode . encodeMsg :: FromServerMessage -> Maybe a - in named (T.pack $ show $ head $ snd $ splitTyConApp $ last $ typeRepArgs $ typeOf parser) $ do - x <- satisfy (isJust . parser) - return $ castMsg x + in named (T.pack $ show $ head $ snd $ splitTyConApp $ last $ typeRepArgs $ typeOf parser) $ + castMsg <$> satisfy (isJust . parser) -- | Matches if the message is a notification. anyNotification :: Session FromServerMessage @@ -87,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