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

Define a function to compute a JSONSummary from an Entry.

This commit is contained in:
Rob Rix 2017-05-10 13:18:47 -04:00
parent 284f358d7a
commit 13d088e6b8

View File

@ -10,6 +10,7 @@ module Renderer.TOC
, declarationAlgebra
, Entry(..)
, tableOfContentsBy
, entrySummary
) where
import Category as C
@ -106,6 +107,14 @@ tableOfContentsBy selector = fromMaybe [] . iter diffAlgebra . fmap (Just . fmap
termAlgebra r | Just a <- selector r = [a]
| otherwise = fold r
-- | Construct a 'JSONSummary' from an 'Entry'. Returns 'Nothing' for 'Unchanged' patches.
entrySummary :: (HasField fields Category, HasField fields (Maybe Declaration), HasField fields SourceSpan) => Entry (Record fields) -> Maybe JSONSummary
entrySummary entry = case entry of
Unchanged _ -> Nothing
Changed a -> Just (recordSummary a "modified")
Patched p -> Just (recordSummary (afterOrBefore p) (patchType p))
where recordSummary record = JSONSummary . Summarizable (category record) (maybe "" declarationIdentifier (getField record :: Maybe Declaration)) (sourceSpan record)
toc :: HasDefaultFields fields => Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Summaries
toc blobs diff = Summaries changes errors
where