diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index 8df0a6dd6..8bd2efee0 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -84,13 +84,13 @@ diffTOC blobs = removeDupes . diffToTOCSummaries >=> toJSONSummaries diffToTOCSummaries :: HasDefaultFields fields => Diff (Syntax Text) (Record fields) -> [TOCSummary DiffInfo] diffToTOCSummaries = para $ \diff -> case diff of Free (Join (_, annotation) :< syntax) - | Just identifier <- identifierFor (textFor (source (Both.snd blobs)) . diffRange) diffUnwrap syntax -> + | Just identifier <- identifierFor (diffSource (source (Both.snd blobs))) diffUnwrap syntax -> foldMap (fmap (contextualize (Summarizable (category annotation) identifier (sourceSpan annotation) "modified")) . snd) syntax | otherwise -> foldMap snd syntax Pure patch -> fmap summarize (sequenceA (runBothWith mapPatch (toInfo . source <$> blobs) patch)) toInfo :: HasDefaultFields fields => Source -> Term (Syntax Text) (Record fields) -> [DiffInfo] - toInfo source = para $ \ (annotation :< syntax) -> let termName = fromMaybe (textFor source (byteRange annotation)) (identifierFor (textFor source . termRange) (Just . unwrap) syntax) in case syntax of + toInfo source = para $ \ (annotation :< syntax) -> let termName = fromMaybe (textFor source (byteRange annotation)) (identifierFor (termSource source) (Just . tailF . runCofree) syntax) in case syntax of S.ParseError{} -> [DiffInfo Nothing termName (sourceSpan annotation)] S.Indexed{} -> foldMap snd syntax S.Fixed{} -> foldMap snd syntax @@ -114,16 +114,18 @@ identifierFor getSource unwrap syntax = case syntax of | otherwise -> Just $ getSource receiver <> "." <> getSource identifier _ -> Nothing -diffRange :: (HasField fields Range, Functor f) => Diff f (Record fields) -> Range -diffRange = iter (byteRange . Both.snd . headF) . fmap (termRange . afterOrBefore) +diffSource :: HasField fields Range => Source -> Diff f (Record fields) -> Text +diffSource source diff = case runFree diff of + Free (a :< _) -> toText (Source.slice (byteRange (Both.snd a)) source) + Pure a -> termSource source (afterOrBefore a) diffUnwrap :: Diff f (Record fields) -> Maybe (f (Diff f (Record fields))) diffUnwrap diff = case runFree diff of Free (_ :< syntax) -> Just syntax _ -> Nothing -termRange :: (HasField fields Range, Functor f) => Term f (Record fields) -> Range -termRange = byteRange . extract +termSource :: HasField fields Range => Source -> Term f (Record fields) -> Text +termSource source = toText . flip Source.slice source . byteRange . headF . runCofree textFor :: Source -> Range -> Text textFor source = toText . flip Source.slice source