1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +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,26 +40,29 @@ 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
where
path = T.pack $ pathKeyForBlobPair blobPair
lang = bridging # languageForBlobPair blobPair
toChangeType = \case instance (Foldable syntax, Functor syntax) => SummarizeDiff (Diff syntax) where
"added" -> Added summarizeDiff blobPair diff = foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff)
"modified" -> Modified where
"removed" -> Removed path = T.pack $ pathKeyForBlobPair blobPair
_ -> None lang = bridging # languageForBlobPair blobPair
go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile toChangeType = \case
go TOCSummary{..} TOCSummaryFile{..} "added" -> Added
= TOCSummaryFile path language (V.cons (TOCSummaryChange summaryCategoryName summaryTermName (converting #? summarySpan) (toChangeType summaryChangeType)) changes) errors "modified" -> Modified
go ErrorSummary{..} TOCSummaryFile{..} "removed" -> Removed
= TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors) _ -> None
go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile
go TOCSummary{..} TOCSummaryFile{..}
= TOCSummaryFile path language (V.cons (TOCSummaryChange summaryCategoryName summaryTermName (converting #? summarySpan) (toChangeType summaryChangeType)) changes) errors
go ErrorSummary{..} TOCSummaryFile{..}
= TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors)