From 82a682ce648c48c890949ad67fc22900448dc94e Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Tue, 31 Jul 2018 11:35:07 +0100 Subject: [PATCH] Add diff to replay error output --- .gitignore | 2 ++ haskell-lsp-test.cabal | 1 + src/Language/Haskell/LSP/Test/Exceptions.hs | 15 +++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index f78eac2..e6ad272 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .stack-work dist +.cabal-sandbox +cabal.sandbox.config dist-newstyle cabal.project.local* .ghc.environment.* diff --git a/haskell-lsp-test.cabal b/haskell-lsp-test.cabal index d3ef940..ec769ac 100644 --- a/haskell-lsp-test.cabal +++ b/haskell-lsp-test.cabal @@ -33,6 +33,7 @@ library , conduit-parse , containers , data-default + , Diff , directory , filepath , lens diff --git a/src/Language/Haskell/LSP/Test/Exceptions.hs b/src/Language/Haskell/LSP/Test/Exceptions.hs index b337f0b..28903dc 100644 --- a/src/Language/Haskell/LSP/Test/Exceptions.hs +++ b/src/Language/Haskell/LSP/Test/Exceptions.hs @@ -3,7 +3,10 @@ module Language.Haskell.LSP.Test.Exceptions where import Control.Exception import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Types -import Data.Aeson +import Data.Aeson.Encode.Pretty +import Data.Algorithm.Diff +import Data.Algorithm.DiffOutput +import Data.List import qualified Data.ByteString.Lazy.Char8 as B data SessionException = Timeout @@ -23,10 +26,14 @@ instance Show SessionException where "Was parsing: " ++ expected ++ "\n" ++ "Last message received: " ++ show lastMsg show (ReplayOutOfOrder received expected) = - "Replay is out of order:\n" ++ + let expected' = nub expected + getJsonDiff = lines . B.unpack . encodePretty + showExp exp = B.unpack (encodePretty exp) ++ "\nDiff:\n" ++ + ppDiff (getGroupedDiff (getJsonDiff received) (getJsonDiff exp)) + in "Replay is out of order:\n" ++ -- Print json so its a bit easier to update the session logs - "Received from server:\n" ++ B.unpack (encode received) ++ "\n" ++ - "Expected one of:\n" ++ unlines (map (B.unpack . encode) expected) + "Received from server:\n" ++ B.unpack (encodePretty received) ++ "\n" ++ + "Expected one of:\n" ++ unlines (map showExp expected') show UnexpectedDiagnostics = "Unexpectedly received diagnostics from the server." show (IncorrectApplyEditRequest msgStr) = "ApplyEditRequest didn't contain document, instead received:\n" ++ msgStr -- 2.30.2