mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +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 = maybeFst . unPatch
|
||||
|
||||
afterOrBefore :: Patch a -> Maybe a
|
||||
afterOrBefore patch = case (before patch, after patch) of
|
||||
(_, Just after) -> Just after
|
||||
(Just before, _) -> Just before
|
||||
(_, _) -> Nothing
|
||||
afterOrBefore :: Patch a -> a
|
||||
afterOrBefore patch = case patch of
|
||||
Insert after -> after
|
||||
Delete before -> before
|
||||
Replace _ after -> after
|
||||
|
||||
-- | Return both sides of a patch.
|
||||
unPatch :: Patch a -> These a a
|
||||
|
@ -103,9 +103,7 @@ diffTOC blobs diff = removeDupes (diffToTOCSummaries (source <$> blobs) diff) >>
|
||||
|
||||
-- Mark which leaves are summarizable.
|
||||
toTOCSummaries :: Patch DiffInfo -> [TOCSummary DiffInfo]
|
||||
toTOCSummaries patch = case afterOrBefore patch of
|
||||
Just diffInfo -> toTOCSummaries' patch diffInfo
|
||||
Nothing -> panic "No diff"
|
||||
toTOCSummaries patch = toTOCSummaries' patch (afterOrBefore patch)
|
||||
where
|
||||
toTOCSummaries' patch' diffInfo = case diffInfo of
|
||||
ErrorInfo{..} -> pure $ TOCSummary patch' NotSummarizable
|
||||
@ -147,9 +145,7 @@ summarizable term = go (unwrap term) term
|
||||
_ -> NotSummarizableTerm
|
||||
|
||||
toJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary]
|
||||
toJSONSummaries TOCSummary{..} = case afterOrBefore summaryPatch of
|
||||
Just diffInfo -> toJSONSummaries' diffInfo
|
||||
Nothing -> panic "No diff"
|
||||
toJSONSummaries TOCSummary{..} = toJSONSummaries' (afterOrBefore summaryPatch)
|
||||
where
|
||||
toJSONSummaries' diffInfo = case diffInfo of
|
||||
ErrorInfo{..} -> pure $ ErrorSummary termName infoSpan
|
||||
|
Loading…
Reference in New Issue
Block a user