1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 20:41:38 +03:00

🔥 InSummarizable.

This commit is contained in:
Rob Rix 2017-05-09 11:16:17 -04:00
parent d38b76f554
commit 490820c79d

View File

@ -22,9 +22,7 @@ data JSONSummary = JSONSummary { info :: Summarizable }
deriving (Generic, Eq, Show)
instance ToJSON JSONSummary where
toJSON JSONSummary{..} = object $ case info of
InSummarizable{..} -> [ "changeType" .= ("modified" :: Text), "category" .= toCategoryName parentCategory, "term" .= parentTermName, "span" .= parentSourceSpan ]
Summarizable{..} -> [ "changeType" .= summarizableChangeType, "category" .= toCategoryName summarizableCategory, "term" .= summarizableTermName, "span" .= summarizableSourceSpan ]
toJSON (JSONSummary Summarizable{..}) = object [ "changeType" .= summarizableChangeType, "category" .= toCategoryName summarizableCategory, "term" .= summarizableTermName, "span" .= summarizableSourceSpan ]
toJSON ErrorSummary{..} = object [ "error" .= error, "span" .= errorSpan ]
isErrorSummary :: JSONSummary -> Bool
@ -51,11 +49,6 @@ data Summarizable
, summarizableSourceSpan :: SourceSpan
, summarizableChangeType :: Text
}
| InSummarizable
{ parentCategory :: Category
, parentTermName :: Text
, parentSourceSpan :: SourceSpan
}
deriving (Eq, Show)
toc :: HasDefaultFields fields => Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Summaries
@ -93,7 +86,7 @@ diffTOC blobs diff = removeDupes (diffToTOCSummaries (source <$> blobs) diff) >>
Free (Join (_, annotation) :< syntax)
| isSummarizable syntax
, Just termName <- toTermName (Both.snd sources) . cofree . (annotation :<) <$> traverse (afterTerm . fst) syntax
, parentInfo <- InSummarizable (category annotation) termName (sourceSpan annotation) ->
, parentInfo <- Summarizable (category annotation) termName (sourceSpan annotation) "modified" ->
foldMap (fmap (contextualize parentInfo) . snd) syntax
| otherwise -> foldMap snd syntax
Pure patch -> fmap summarize (sequenceA (runBothWith mapPatch (toInfo <$> sources) patch))