1
1
mirror of https://github.com/github/semantic.git synced 2025-01-08 08:30:27 +03:00

Improve diff tree JSON output

This commit is contained in:
Timothy Clem 2017-12-13 13:43:59 -08:00
parent 0e986cfab2
commit 161002486f

View File

@ -6,7 +6,8 @@ module Rendering.JSON
import Data.Aeson (ToJSON, toJSON, object, (.=)) import Data.Aeson (ToJSON, toJSON, object, (.=))
import Data.Aeson as A import Data.Aeson as A
import Data.Blob import Data.Blob
import Data.Bifoldable (biList) import Data.Bifunctor
import Data.Bifoldable
import Data.Bifunctor.Join import Data.Bifunctor.Join
import Data.Language import Data.Language
import qualified Data.Map as Map import qualified Data.Map as Map
@ -15,10 +16,10 @@ import GHC.Generics
-- | Render a diff to a string representing its JSON. -- | Render a diff to a string representing its JSON.
renderJSONDiff :: ToJSON a => BlobPair -> a -> Map.Map Text Value renderJSONDiff :: ToJSON a => BlobPair -> a -> Map.Map Text Value
renderJSONDiff blobs diff = Map.fromList renderJSONDiff blobs diff = Map.fromList $ ("diff", toJSON diff) : renderJSONBlobPair
[ ("diff", toJSON diff) where
, ("paths", toJSON (blobPath <$> (biList . runJoin) blobs)) renderJSONBlobPair = biList (bimap (render "before") (render "after") (runJoin blobs))
] render key Blob{..} = (key, toJSON (object [ "path" .= blobPath, "language" .= blobLanguage ]))
data File a = File { filePath :: FilePath, fileLanguage :: Maybe Language, fileContent :: a } data File a = File { filePath :: FilePath, fileLanguage :: Maybe Language, fileContent :: a }
deriving (Generic, Show) deriving (Generic, Show)