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:
parent
8d3c4e4250
commit
1079b7a3a7
|
@ -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
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[ …
|
||||
, { y = - 4
|
||||
+ 5
|
||||
, …
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
[ { x = 1, y = 2 }
|
||||
, { x = 3, y = 4 }
|
||||
]
|
|
@ -0,0 +1,3 @@
|
|||
[ { x = 1, y = 2 }
|
||||
, { x = 3, y = 5 }
|
||||
]
|
Loading…
Reference in New Issue