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

Define a toc2 function depending on declarations in the annotations.

This commit is contained in:
Rob Rix 2017-05-10 14:00:58 -04:00
parent 13d088e6b8
commit 066b2cb965

View File

@ -1,6 +1,7 @@
{-# LANGUAGE RankNTypes #-}
module Renderer.TOC
( toc
, toc2
, diffTOC
, JSONSummary(..)
, Summarizable(..)
@ -115,6 +116,17 @@ entrySummary entry = case entry of
Patched p -> Just (recordSummary (afterOrBefore p) (patchType p))
where recordSummary record = JSONSummary . Summarizable (category record) (maybe "" declarationIdentifier (getField record :: Maybe Declaration)) (sourceSpan record)
toc2 :: (HasField fields Category, HasField fields (Maybe Declaration), HasField fields SourceSpan) => Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Summaries
toc2 blobs = uncurry Summaries . bimap toMap toMap . List.partition isErrorSummary . mapMaybe entrySummary . dedupe . tableOfContentsBy declaration
where toMap [] = mempty
toMap as = Map.singleton summaryKey (toJSON <$> as)
dedupe = identity
summaryKey = toS $ case runJoin (path <$> blobs) of
(before, after) | null before -> after
| null after -> before
| before == after -> after
| otherwise -> before <> " -> " <> after
toc :: HasDefaultFields fields => Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Summaries
toc blobs diff = Summaries changes errors
where