1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 21:16:12 +03:00

Straightforward json encoding

This commit is contained in:
Timothy Clem 2017-03-08 13:40:27 -08:00
parent 58889e1038
commit 0cc056c06b

View File

@ -1,13 +1,13 @@
module Renderer (Renderer, Output(..), concatOutputs, toSummaryKey, Format(..)) where
import Data.Aeson (Value, toEncoding)
import Data.Aeson.Encoding (encodingToLazyByteString)
import Data.Aeson (Value, encode)
import Data.Functor.Both
import Data.Map as Map hiding (null)
import Data.Text.Encoding (encodeUtf8)
import Data.ByteString.Lazy (toStrict)
import qualified Data.ByteString as B
import Data.Functor.Listable
import Prologue
import Prologue hiding (toStrict)
import Source (SourceBlob)
import Syntax
import Diff
@ -39,12 +39,12 @@ toSummaryKey = runBothWith $ \before after ->
-- changes and errors.
-- Split and Patch output is appended together with newlines.
concatOutputs :: [Output] -> ByteString
concatOutputs list | isJSON list = toS . encodingToLazyByteString . toEncoding $ concatJSON list
concatOutputs list | isJSON list = toStrict . encode $ concatJSON list
where
concatJSON :: [Output] -> Map Text Value
concatJSON (JSONOutput hash : rest) = Map.union hash (concatJSON rest)
concatJSON _ = mempty
concatOutputs list | isSummary list = toS . encodingToLazyByteString . toEncoding $ concatSummaries list
concatOutputs list | isSummary list = toStrict . encode $ concatSummaries list
where
concatSummaries :: [Output] -> Map Text (Map Text [Value])
concatSummaries (SummaryOutput hash : rest) = Map.unionWith (Map.unionWith (<>)) hash (concatSummaries rest)