diff --git a/src/Command.hs b/src/Command.hs index 23a56c030..d64fe74dd 100644 --- a/src/Command.hs +++ b/src/Command.hs @@ -6,6 +6,7 @@ module Command import Command.Diff as C import Command.Parse as C import Control.Monad.Free.Freer +import Data.Functor.Both import Data.List ((\\)) import Data.RandomWalkSimilarity import Data.Record @@ -22,6 +23,7 @@ import Git.Types import GitmonClient import Language import Prologue +import Renderer import Source import Syntax import Term @@ -34,8 +36,9 @@ data CommandF f where Diff :: Term (Syntax Text) (Record DefaultFields) -> Term (Syntax Text) (Record DefaultFields) -> CommandF (Diff (Syntax Text) (Record DefaultFields)) + RenderDiff :: DiffRenderer fields output -> SourceBlob -> SourceBlob -> Diff (Syntax Text) (Record fields) -> CommandF output + -- render a term - -- render a diff -- parallelize diffs of a list of paths + git shas -- explicit gitmon effects/events @@ -107,3 +110,6 @@ runCommand = iterFreerA $ \ command yield -> case command of getLabel (h :< t) = (Info.category h, case t of Leaf s -> Just s _ -> Nothing) + + RenderDiff renderer blob1 blob2 diff -> + yield (runDiffRenderer' renderer (both blob1 blob2) diff) diff --git a/src/Renderer.hs b/src/Renderer.hs index 5080b0208..07e76daab 100644 --- a/src/Renderer.hs +++ b/src/Renderer.hs @@ -36,8 +36,8 @@ data DiffRenderer fields output where SExpressionDiffRenderer :: (HasField fields Category, HasField fields SourceSpan) => SExpressionFormat -> DiffRenderer fields ByteString ToCRenderer :: HasDefaultFields fields => DiffRenderer fields (Map Text (Map Text [Value])) -runDiffRenderer :: Both SourceBlob -> Diff (Syntax Text) (Record fields) -> DiffRenderer fields output -> Output -runDiffRenderer sources diff renderer = case renderer of +runDiffRenderer :: DiffRenderer fields output -> Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Output +runDiffRenderer renderer sources diff = case renderer of SplitRenderer -> SplitOutput (R.split sources diff) PatchRenderer -> PatchOutput (R.patch sources diff) JSONDiffRenderer -> JSONOutput (R.json sources diff) @@ -45,8 +45,8 @@ runDiffRenderer sources diff renderer = case renderer of SExpressionDiffRenderer format -> SExpressionOutput (R.sExpression format sources diff) ToCRenderer -> TOCOutput (R.toc sources diff) -runDiffRenderer' :: Both SourceBlob -> Diff (Syntax Text) (Record fields) -> DiffRenderer fields output -> output -runDiffRenderer' sources diff renderer = case renderer of +runDiffRenderer' :: DiffRenderer fields output -> Both SourceBlob -> Diff (Syntax Text) (Record fields) -> output +runDiffRenderer' renderer sources diff = case renderer of SplitRenderer -> R.split sources diff PatchRenderer -> R.patch sources diff JSONDiffRenderer -> R.json sources diff