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:
parent
cb77c1b810
commit
def8e1b6fb
@ -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.
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user