Improve diffs for lists (#1585)

Now the diff for lists will descend into diffs for elements when reasonable to
do so
This commit is contained in:
Gabriel Gonzalez 2019-12-03 09:17:43 -08:00 committed by mergify[bot]
parent 8d3c4e4250
commit 1079b7a3a7
4 changed files with 24 additions and 3 deletions

View File

@ -361,15 +361,23 @@ diffChunks cL cR
diffList
:: (Eq a, Pretty a)
=> Seq (Expr Void a) -> Seq (Expr Void a) -> Diff
diffList l r = bracketed (foldMap diffPart parts)
diffList l r = bracketed (loop parts)
where
-- Sections of the list that are only in left, only in right, or in both
parts =
Algo.Diff.getGroupedDiffBy ((same .) . diff) (toList l) (toList r)
parts = Algo.Diff.getGroupedDiffBy equal (toList l) (toList r)
equal a b = same (diff a b)
-- Render each element of a list using an extra rendering function f
prettyElems f = map (f . token . Internal.prettyExpr)
loop [] =
mempty
loop (Algo.Diff.First as : Algo.Diff.Second bs : parts)
| length as == length bs = zipWith diff as bs <> loop parts
loop (part : parts) =
diffPart part <> loop parts
diffPart part =
case part of
-- Only present in left

View File

@ -0,0 +1,7 @@
[ …
, { y = - 4
+ 5
, …
}
]

View File

@ -0,0 +1,3 @@
[ { x = 1, y = 2 }
, { x = 3, y = 4 }
]

View File

@ -0,0 +1,3 @@
[ { x = 1, y = 2 }
, { x = 3, y = 5 }
]