1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Add a toPrettyDiff function to abstract the construction of pretty diffs away.

This commit is contained in:
Rob Rix 2016-05-24 13:04:10 -04:00
parent 24a732322c
commit e0e7f0fa4a

View File

@ -218,6 +218,11 @@ toAlignedChildren = join . (`evalState` both 0 0) . mapM go
put $ (+) <$> prev <*> modifyJoin (fromThese 0 0) (length <$> contents) put $ (+) <$> prev <*> modifyJoin (fromThese 0 0) (length <$> contents)
return [] return []
toPrettyDiff :: [BranchElement] -> PrettyDiff [(String, Range)]
toPrettyDiff elements = PrettyDiff sources (alignBranch id children ranges)
where (sources, ranges) = toSourcesAndRanges elements
children = toAlignedChildren elements
instance Arbitrary BranchElement where instance Arbitrary BranchElement where
arbitrary = oneof [ key >>= \ key -> Child key <$> joinTheseOf (contents key) arbitrary = oneof [ key >>= \ key -> Child key <$> joinTheseOf (contents key)
, Margin <$> joinTheseOf margin ] , Margin <$> joinTheseOf margin ]