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

Move the guts of summarizeDiff into TOCSummaries.

This commit is contained in:
Rob Rix 2019-10-16 22:11:36 -04:00
parent cb77c1b810
commit def8e1b6fb
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7
2 changed files with 23 additions and 25 deletions

View File

@ -174,33 +174,11 @@ summarizeDiffParsers = aLaCarteParsers
class DiffTerms term => SummarizeDiff term where class DiffTerms term => SummarizeDiff term where
decorateTerm :: Blob -> term Loc -> term (Maybe Declaration) decorateTerm :: Blob -> term Loc -> term (Maybe Declaration)
summarizeDiff :: BlobPair -> DiffFor term (Maybe Declaration) (Maybe Declaration) -> TOCSummaryFile summarizeDiff :: DiffFor term (Maybe Declaration) (Maybe Declaration) -> [TOCSummary]
instance (Diffable syntax, Eq1 syntax, HasDeclaration syntax, Hashable1 syntax, Traversable syntax) => SummarizeDiff (Term syntax) where instance (Diffable syntax, Eq1 syntax, HasDeclaration syntax, Hashable1 syntax, Traversable syntax) => SummarizeDiff (Term syntax) where
decorateTerm = decoratorWithAlgebra . declarationAlgebra decorateTerm = decoratorWithAlgebra . declarationAlgebra
summarizeDiff blobPair diff = foldr go (defMessage & P.path .~ path & P.language .~ lang) (diffTOC diff) summarizeDiff = diffTOC
where
path = T.pack $ pathKeyForBlobPair blobPair
lang = bridging # languageForBlobPair blobPair
toChangeType = \case
"added" -> ADDED
"modified" -> MODIFIED
"removed" -> REMOVED
_ -> NONE
go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile
go TOCSummary{..} file = defMessage
& P.path .~ file^.P.path
& P.language .~ file^.P.language
& P.changes .~ (defMessage & P.category .~ summaryCategoryName & P.term .~ summaryTermName & P.maybe'span .~ (converting #? summarySpan) & P.changeType .~ toChangeType summaryChangeType) : file^.P.changes
& P.errors .~ file^.P.errors
go ErrorSummary{..} file = defMessage
& P.path .~ file^.P.path
& P.language .~ file^.P.language
& P.changes .~ file^.P.changes
& P.errors .~ (defMessage & P.error .~ errorText & P.maybe'span .~ converting #? errorSpan) : file^.P.errors
-- | Parse a 'BlobPair' using one of the provided parsers, diff the resulting terms, and run an action on the abstracted diff. -- | Parse a 'BlobPair' using one of the provided parsers, diff the resulting terms, and run an action on the abstracted diff.

View File

@ -1,3 +1,4 @@
{-# LANGUAGE LambdaCase #-}
module Semantic.Api.TOCSummaries (diffSummary, legacyDiffSummary, diffSummaryBuilder) where module Semantic.Api.TOCSummaries (diffSummary, legacyDiffSummary, diffSummaryBuilder) where
import Control.Effect.Error import Control.Effect.Error
@ -37,7 +38,7 @@ diffSummary blobs = do
pure $ defMessage & P.files .~ diff pure $ defMessage & P.files .~ diff
where where
go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile
go blobPair = decoratingDiffWith summarizeDiffParsers decorateTerm (pure . summarizeDiff blobPair) blobPair go blobPair = decoratingDiffWith summarizeDiffParsers decorateTerm (pure . foldr combine (defMessage & P.path .~ path & P.language .~ lang) . summarizeDiff) blobPair
`catchError` \(SomeException e) -> `catchError` \(SomeException e) ->
pure $ defMessage pure $ defMessage
& P.path .~ path & P.path .~ path
@ -46,3 +47,22 @@ diffSummary blobs = do
& P.errors .~ [defMessage & P.error .~ T.pack (show e) & P.maybe'span .~ Nothing] & P.errors .~ [defMessage & P.error .~ T.pack (show e) & P.maybe'span .~ Nothing]
where path = T.pack $ pathKeyForBlobPair blobPair where path = T.pack $ pathKeyForBlobPair blobPair
lang = bridging # languageForBlobPair blobPair lang = bridging # languageForBlobPair blobPair
toChangeType = \case
"added" -> ADDED
"modified" -> MODIFIED
"removed" -> REMOVED
_ -> NONE
combine :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile
combine TOCSummary{..} file = defMessage
& P.path .~ file^.P.path
& P.language .~ file^.P.language
& P.changes .~ (defMessage & P.category .~ summaryCategoryName & P.term .~ summaryTermName & P.maybe'span .~ (converting #? summarySpan) & P.changeType .~ toChangeType summaryChangeType) : file^.P.changes
& P.errors .~ file^.P.errors
combine ErrorSummary{..} file = defMessage
& P.path .~ file^.P.path
& P.language .~ file^.P.language
& P.changes .~ file^.P.changes
& P.errors .~ (defMessage & P.error .~ errorText & P.maybe'span .~ converting #? errorSpan) : file^.P.errors