diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 765c3a2a8..6545fdb84 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -174,33 +174,11 @@ summarizeDiffParsers = aLaCarteParsers class DiffTerms term => SummarizeDiff term where 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 decorateTerm = decoratorWithAlgebra . declarationAlgebra - summarizeDiff blobPair diff = foldr go (defMessage & P.path .~ path & P.language .~ lang) (diffTOC diff) - 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 + summarizeDiff = diffTOC -- | Parse a 'BlobPair' using one of the provided parsers, diff the resulting terms, and run an action on the abstracted diff. diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index 5f71596ce..6a6487007 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE LambdaCase #-} module Semantic.Api.TOCSummaries (diffSummary, legacyDiffSummary, diffSummaryBuilder) where import Control.Effect.Error @@ -37,7 +38,7 @@ diffSummary blobs = do pure $ defMessage & P.files .~ diff where 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) -> pure $ defMessage & P.path .~ path @@ -46,3 +47,22 @@ diffSummary blobs = do & P.errors .~ [defMessage & P.error .~ T.pack (show e) & P.maybe'span .~ Nothing] where path = T.pack $ pathKeyForBlobPair 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