From f8ecbf92868dbd09b59f995dfdd6a5f518f7c9e5 Mon Sep 17 00:00:00 2001 From: joshvera Date: Mon, 23 Jan 2017 12:16:59 -0500 Subject: [PATCH] WIP stub TOC renderer --- src/Renderer/TOC.hs | 58 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index c9ba3e9d0..37ff47734 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -1,8 +1,62 @@ +{-# LANGUAGE ScopedTypeVariables #-} module Renderer.TOC where +import Prologue +import Patch import Renderer import Data.Record import Info +import Data.Functor.Both hiding (fst, snd) +import Source +import Diff + + +{- + +TOCSummary (Patch DiffInfo) [Identifiable (Category, Text), Annotatable] + +{ + "changes": [ + { FilePath: [ {SourceSpan, TermContext, TermType, ChangeType} ] } + ], + "errors": [ + { FilePath: [ {SourceSpan, ErrorText } ] } + ] +} +-} + +data JSONSummary = JSONSummary { span :: SourceSpan, termContext :: Text, contextType :: Text, changeType :: Text } + +data DiffInfo = LeafInfo { leafCategory :: Category, termName :: Text, sourceSpan :: SourceSpan } + | BranchInfo { branches :: [ DiffInfo ], branchCategory :: Category } + | ErrorInfo { errorSpan :: SourceSpan, termName :: Text } + | HideInfo -- Hide/Strip from summary output entirely. + deriving (Eq, Show) + +data TOCSummary a = TOCSummary { + patch :: Patch a, + parentAnnotation :: [Either (Category, Text) (Category, Text)] +} deriving (Eq, Functor, Show, Generic) + +toc :: (StringConv leaf Text, DefaultFields fields) => Both SourceBlob -> SyntaxDiff leaf fields -> [TOCSummary DiffInfo] +toc blobs diff = tocToJSONSummaries =<< diffToTOC (source <$> blobs) diff + +diffToTOC :: (StringConv leaf Text, DefaultFields fields) => Both (Source Char) -> SyntaxDiff leaf fields -> [TOCSummary DiffInfo] +diffToTOC = _ + +tocToJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary] +tocToJSONSummaries TOCSummary{..} = + +-- If the term is a method/function grab the term type, name, and span here, otherwise grab them up top. +summaries :: Patch DiffInfo -> [TOCSummary (Maybe Text) (Maybe Text) (Maybe SourceSpans)] +summaries = \case + p@(Replace i1 i2) -> zipWith (\a b -> + TOCSummary + { + changeType = "replace" + termContext = + , span = SourceSpans $ These (span a) (span b) + }) (toLeafInfos i1) (toLeafInfos i2) + p@(Insert info) -> prefixWithPatch p That <$> toLeafInfos info + p@(Delete info) -> prefixWithPatch p This <$> toLeafInfos info -toc :: (HasField fields Category, HasField fields Cost, HasField fields Range) => Renderer (Record fields) -toc sources diff = TOCOutput [] \ No newline at end of file