mirror of
https://github.com/github/semantic.git
synced 2025-01-03 13:02:37 +03:00
afterOrBefore always returns a value.
This commit is contained in:
parent
8023631dfb
commit
8cd74f6ea2
10
src/Patch.hs
10
src/Patch.hs
@ -51,11 +51,11 @@ after = maybeSnd . unPatch
|
|||||||
before :: Patch a -> Maybe a
|
before :: Patch a -> Maybe a
|
||||||
before = maybeFst . unPatch
|
before = maybeFst . unPatch
|
||||||
|
|
||||||
afterOrBefore :: Patch a -> Maybe a
|
afterOrBefore :: Patch a -> a
|
||||||
afterOrBefore patch = case (before patch, after patch) of
|
afterOrBefore patch = case patch of
|
||||||
(_, Just after) -> Just after
|
Insert after -> after
|
||||||
(Just before, _) -> Just before
|
Delete before -> before
|
||||||
(_, _) -> Nothing
|
Replace _ after -> after
|
||||||
|
|
||||||
-- | Return both sides of a patch.
|
-- | Return both sides of a patch.
|
||||||
unPatch :: Patch a -> These a a
|
unPatch :: Patch a -> These a a
|
||||||
|
@ -103,9 +103,7 @@ diffTOC blobs diff = removeDupes (diffToTOCSummaries (source <$> blobs) diff) >>
|
|||||||
|
|
||||||
-- Mark which leaves are summarizable.
|
-- Mark which leaves are summarizable.
|
||||||
toTOCSummaries :: Patch DiffInfo -> [TOCSummary DiffInfo]
|
toTOCSummaries :: Patch DiffInfo -> [TOCSummary DiffInfo]
|
||||||
toTOCSummaries patch = case afterOrBefore patch of
|
toTOCSummaries patch = toTOCSummaries' patch (afterOrBefore patch)
|
||||||
Just diffInfo -> toTOCSummaries' patch diffInfo
|
|
||||||
Nothing -> panic "No diff"
|
|
||||||
where
|
where
|
||||||
toTOCSummaries' patch' diffInfo = case diffInfo of
|
toTOCSummaries' patch' diffInfo = case diffInfo of
|
||||||
ErrorInfo{..} -> pure $ TOCSummary patch' NotSummarizable
|
ErrorInfo{..} -> pure $ TOCSummary patch' NotSummarizable
|
||||||
@ -147,9 +145,7 @@ summarizable term = go (unwrap term) term
|
|||||||
_ -> NotSummarizableTerm
|
_ -> NotSummarizableTerm
|
||||||
|
|
||||||
toJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary]
|
toJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary]
|
||||||
toJSONSummaries TOCSummary{..} = case afterOrBefore summaryPatch of
|
toJSONSummaries TOCSummary{..} = toJSONSummaries' (afterOrBefore summaryPatch)
|
||||||
Just diffInfo -> toJSONSummaries' diffInfo
|
|
||||||
Nothing -> panic "No diff"
|
|
||||||
where
|
where
|
||||||
toJSONSummaries' diffInfo = case diffInfo of
|
toJSONSummaries' diffInfo = case diffInfo of
|
||||||
ErrorInfo{..} -> pure $ ErrorSummary termName infoSpan
|
ErrorInfo{..} -> pure $ ErrorSummary termName infoSpan
|
||||||
|
Loading…
Reference in New Issue
Block a user