1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 10:27:45 +03:00

Summarize diffs using an abstract interface.

This commit is contained in:
Rob Rix 2019-10-01 22:29:29 -04:00
parent e5685f9f5c
commit f08ac25116
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7

View File

@ -40,14 +40,17 @@ diffSummary :: DiffEffects sig m => [BlobPair] -> m DiffTreeTOCResponse
diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go
where where
go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile
go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (pure . summarizeDiff blobPair) blobPair
`catchError` \(SomeException e) -> `catchError` \(SomeException e) ->
pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing]) pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing])
where path = T.pack $ pathKeyForBlobPair blobPair where path = T.pack $ pathKeyForBlobPair blobPair
lang = bridging # languageForBlobPair blobPair lang = bridging # languageForBlobPair blobPair
render :: (Foldable syntax, Functor syntax, Applicative m) => BlobPair -> Diff syntax (Maybe Declaration) (Maybe Declaration) -> m TOCSummaryFile class SummarizeDiff diff where
render blobPair diff = pure $ foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff) summarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> TOCSummaryFile
instance (Foldable syntax, Functor syntax) => SummarizeDiff (Diff syntax) where
summarizeDiff blobPair diff = foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff)
where where
path = T.pack $ pathKeyForBlobPair blobPair path = T.pack $ pathKeyForBlobPair blobPair
lang = bridging # languageForBlobPair blobPair lang = bridging # languageForBlobPair blobPair