projects
/
lsp-test.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Pretty print message trace
[lsp-test.git]
/
src
/
Language
/
Haskell
/
LSP
/
Test
/
Parsing.hs
diff --git
a/src/Language/Haskell/LSP/Test/Parsing.hs
b/src/Language/Haskell/LSP/Test/Parsing.hs
index 3ecc53888b31f5090b64344a866d512b5dd1460b..2936b31347f9db69ecf4b1a3951c552336953cfb 100644
(file)
--- 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 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
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
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
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
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
-- | 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 })
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
-- | Matches if the message is a log message notification or a show message notification/request.
loggingNotification :: Session FromServerMessage
loggingNotification = named "Logging notification" $ satisfy shouldSkip