mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Contextualize summaries in diffToTOCSummaries directly.
This commit is contained in:
parent
9df2a73e38
commit
2e98b4570d
@ -90,13 +90,22 @@ diffTOC blobs diff = removeDupes (diffToTOCSummaries (source <$> blobs) diff) >>
|
|||||||
(_, _) -> False
|
(_, _) -> False
|
||||||
|
|
||||||
diffToTOCSummaries :: (StringConv leaf Text, HasDefaultFields fields) => Both Source -> SyntaxDiff leaf fields -> [TOCSummary DiffInfo]
|
diffToTOCSummaries :: (StringConv leaf Text, HasDefaultFields fields) => Both Source -> SyntaxDiff leaf fields -> [TOCSummary DiffInfo]
|
||||||
diffToTOCSummaries sources = para $ \diff ->
|
diffToTOCSummaries sources = para $ \diff -> case first (toTOCSummaries . runBothWith mapPatch toInfo) diff of
|
||||||
let diff' = free (Prologue.fst <$> diff)
|
Free (annotations :< syntax) -> toList diff >>= \ summaries ->
|
||||||
in case first (toTOCSummaries . runBothWith mapPatch toInfo) diff of
|
fmap (contextualize (Both.snd sources) (Both.snd annotations :< fmap fst syntax)) (snd summaries)
|
||||||
Free _ -> mapToInSummarizable sources diff' (toList diff >>= snd)
|
|
||||||
Pure summaries -> summaries
|
Pure summaries -> summaries
|
||||||
where toInfo = termToDiffInfo <$> sources
|
where toInfo = termToDiffInfo <$> sources
|
||||||
|
|
||||||
|
contextualize source (annotation :< syntax) summary
|
||||||
|
| NotSummarizable <- parentInfo summary
|
||||||
|
, isSummarizable syntax
|
||||||
|
, Just terms <- traverse afterTerm syntax = summary { parentInfo = InSummarizable (category annotation) (toTermName 0 source (cofree (annotation :< terms))) (sourceSpan annotation) }
|
||||||
|
| otherwise = summary
|
||||||
|
|
||||||
|
isSummarizable S.Method{} = True
|
||||||
|
isSummarizable S.Function{} = True
|
||||||
|
isSummarizable _ = False
|
||||||
|
|
||||||
-- 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 = case afterOrBefore patch of
|
||||||
@ -118,23 +127,6 @@ toLeafInfos :: DiffInfo -> [DiffInfo]
|
|||||||
toLeafInfos BranchInfo{..} = branches >>= toLeafInfos
|
toLeafInfos BranchInfo{..} = branches >>= toLeafInfos
|
||||||
toLeafInfos leaf = [leaf]
|
toLeafInfos leaf = [leaf]
|
||||||
|
|
||||||
mapToInSummarizable :: forall leaf fields. HasDefaultFields fields => Both Source -> SyntaxDiff leaf fields -> [TOCSummary DiffInfo] -> [TOCSummary DiffInfo]
|
|
||||||
mapToInSummarizable sources diff children = case (beforeTerm diff, afterTerm diff) of
|
|
||||||
(_, Just diff') -> mapToInSummarizable' (Both.snd sources) diff' <$> children
|
|
||||||
(Just diff', _) -> mapToInSummarizable' (Both.fst sources) diff' <$> children
|
|
||||||
(Nothing, Nothing) -> []
|
|
||||||
where
|
|
||||||
mapToInSummarizable' :: Source -> SyntaxTerm leaf fields -> TOCSummary DiffInfo -> TOCSummary DiffInfo
|
|
||||||
mapToInSummarizable' source term summary =
|
|
||||||
case parentInfo summary of
|
|
||||||
NotSummarizable | isSummarizable term ->
|
|
||||||
summary { parentInfo = InSummarizable (category (extract term)) (toTermName 0 source term) (sourceSpan (extract term)) }
|
|
||||||
_ -> summary
|
|
||||||
isSummarizable term = case unwrap term of
|
|
||||||
S.Method{} -> True
|
|
||||||
S.Function{} -> True
|
|
||||||
_ -> False
|
|
||||||
|
|
||||||
toJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary]
|
toJSONSummaries :: TOCSummary DiffInfo -> [JSONSummary]
|
||||||
toJSONSummaries TOCSummary{..} = toJSONSummaries' (afterOrBefore summaryPatch)
|
toJSONSummaries TOCSummary{..} = toJSONSummaries' (afterOrBefore summaryPatch)
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user