From 4e1b48a3564a347c7ef946cf13873f5fd7127f83 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 9 Mar 2016 04:09:35 -0500 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20pass=20in=20the=20adjoining=20f?= =?UTF-8?q?unction.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Alignment.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index c837c558d..39ed16a9d 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -63,12 +63,12 @@ splitAbstractedTerm makeTerm source (Info range categories) syntax = case syntax splitAnnotatedByLines :: (Info -> Syntax leaf outTerm -> outTerm) -> Both (Source Char) -> Both Info -> Syntax leaf [Row (outTerm, Range)] -> [Row (outTerm, Range)] splitAnnotatedByLines makeTerm sources infos syntax = case syntax of Leaf a -> zipDefaults (pure mempty) $ fmap <$> ((\ categories range -> pure (makeTerm (Info range categories) (Leaf a), range)) <$> (Diff.categories <$> infos)) <*> (actualLineRanges <$> (characterRange <$> infos) <*> sources) - Indexed children -> adjoinChildren sources infos (zipDefaults mempty) (adjoinRowsBy (openRangePair <$> sources)) makeTerm (Indexed . fmap copoint) (Identity <$> children) - Fixed children -> adjoinChildren sources infos (zipDefaults mempty) (adjoinRowsBy (openRangePair <$> sources)) makeTerm (Fixed . fmap copoint) (Identity <$> children) - Keyed children -> adjoinChildren sources infos (zipDefaults mempty) (adjoinRowsBy (openRangePair <$> sources)) makeTerm (Keyed . Map.fromList) (List.sortOn (rowRanges . Prelude.snd) $ Map.toList children) + Indexed children -> adjoinChildren sources infos (zipDefaults mempty) makeTerm (Indexed . fmap copoint) (Identity <$> children) + Fixed children -> adjoinChildren sources infos (zipDefaults mempty) makeTerm (Fixed . fmap copoint) (Identity <$> children) + Keyed children -> adjoinChildren sources infos (zipDefaults mempty) makeTerm (Keyed . Map.fromList) (List.sortOn (rowRanges . Prelude.snd) $ Map.toList children) -adjoinChildren :: (Copointed c, Functor c, Applicative f, Foldable f) => f (Source Char) -> f Info -> (f [Line (Maybe (c a), Range)] -> [f (Line (Maybe (c a), Range))]) -> (f (Line (Maybe (c a), Range)) -> [f (Line (Maybe (c a), Range))] -> [f (Line (Maybe (c a), Range))]) -> (Info -> Syntax leaf outTerm -> outTerm) -> ([c a] -> Syntax leaf outTerm) -> [c [f (Line (a, Range))]] -> [f (Line (outTerm, Range))] -adjoinChildren sources infos align adjoin makeTerm constructor children = +adjoinChildren :: (Copointed c, Functor c, Applicative f, Foldable f) => f (Source Char) -> f Info -> (f [Line (Maybe (c a), Range)] -> [f (Line (Maybe (c a), Range))]) -> (Info -> Syntax leaf outTerm -> outTerm) -> ([c a] -> Syntax leaf outTerm) -> [c [f (Line (a, Range))]] -> [f (Line (outTerm, Range))] +adjoinChildren sources infos align makeTerm constructor children = fmap wrap . foldr adjoin [] $ align leadingContext ++ lines where (lines, next) = foldr (childLines sources align) ([], end <$> ranges) children @@ -76,6 +76,8 @@ adjoinChildren sources infos align adjoin makeTerm constructor children = categories = Diff.categories <$> infos leadingContext = fmap (pure . (,) Nothing) <$> (actualLineRanges <$> (Range <$> (start <$> ranges) <*> next) <*> sources) wrap = (wrapLineContents <$> (makeBranchTerm (\ info -> makeTerm info . constructor) <$> categories <*> next) <*>) + adjoin row [] = [ row ] + adjoin row (nextRow : rows) = align (coalesceLinesBy <$> (openRangePair <$> sources) <*> row <*> nextRow) ++ rows childLines :: (Copointed c, Functor c, Applicative f, Foldable f) => f (Source Char) -> (f [Line (Maybe (c a), Range)] -> [f (Line (Maybe (c a), Range))]) -> c [f (Line (a, Range))] -> ([f (Line (Maybe (c a), Range))], f Int) -> ([f (Line (Maybe (c a), Range))], f Int) -- We depend on source ranges increasing monotonically. If a child invalidates that, e.g. if it’s a move in a Keyed node, we don’t output rows for it in this iteration. (It will still show up in the diff as context rows.) This works around https://github.com/github/semantic-diff/issues/488.