1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 14:54:16 +03:00

Stub in grouping children by line with a recursive function.

This commit is contained in:
Rob Rix 2016-03-24 11:05:57 -04:00
parent 88641e5398
commit 99d73906bc

View File

@ -131,10 +131,12 @@ alignDiff sources diff = iter alignSyntax (alignPatch sources <$> diff)
where lineRanges = runBothWith ((Join .) . These) (actualLineRanges <$> (characterRange <$> infos) <*> sources) where lineRanges = runBothWith ((Join .) . These) (actualLineRanges <$> (characterRange <$> infos) <*> sources)
groupChildrenByLine :: Join These [Range] -> [AlignedDiff leaf] -> [Join These (Range, [SplitDiff leaf Info])] groupChildrenByLine :: Join These [Range] -> [AlignedDiff leaf] -> [Join These (Range, [SplitDiff leaf Info])]
groupChildrenByLine lineRanges children = Join . bimap (selectChildrenBy maybeFst) (selectChildrenBy maybeSnd) . runJoin <$> sequenceL lineRanges groupChildrenByLine ranges children = go rangeLists children
where getRange (Free (Annotated (Info range _) _)) = range where go ranges children | (l:ls, r:rs) <- ranges,
getRange (Pure patch) | Info range _ :< _ <- getSplitTerm patch = range ((firstLine:restOfLines):rest) <- children = go ranges (restOfLines:rest)
selectChildrenBy select range = (range, children >>= filter (intersects range . getRange) . catMaybes . fmap (select . runJoin)) | ([]:rest) <- children = go ranges rest
| otherwise = uncurry (alignWith (fmap (flip (,) []) . Join)) ranges
rangeLists = these (flip (,) []) ((,) []) (,) (runJoin ranges)
intersects :: Range -> Range -> Bool intersects :: Range -> Range -> Bool
intersects a b = max (start a) (start b) < min (end a) (end b) intersects a b = max (start a) (start b) < min (end a) (end b)