1
1
mirror of https://github.com/github/semantic.git synced 2024-12-11 08:45:48 +03:00

Apply renderers to blobs up front.

This commit is contained in:
Rob Rix 2017-05-31 12:05:28 -04:00
parent f3d99dc300
commit cc94e45436
2 changed files with 11 additions and 11 deletions

View File

@ -49,26 +49,26 @@ parseDiffAndRenderBlobPair renderer blobs = case renderer of
terms <- distributeFor blobs $ \ blob -> do
term <- parseSource blob
decorate (declarationAlgebra (source blob)) term
diffAndRenderTermPair blobs (runBothWith diffTerms) renderToC terms
diffAndRenderTermPair blobs (runBothWith diffTerms) (renderToC blobs) terms
JSONDiffRenderer -> do
terms <- distributeFor blobs (decorate identifierAlgebra <=< parseSource)
diffAndRenderTermPair blobs (runBothWith diffTerms) renderJSONDiff terms
PatchDiffRenderer -> distributeFor blobs parseSource >>= diffAndRenderTermPair blobs (runBothWith diffTerms) renderPatch
diffAndRenderTermPair blobs (runBothWith diffTerms) (renderJSONDiff blobs) terms
PatchDiffRenderer -> distributeFor blobs parseSource >>= diffAndRenderTermPair blobs (runBothWith diffTerms) (renderPatch blobs)
SExpressionDiffRenderer -> case effectiveLanguage of
Just Language.Python -> distributeFor blobs parseSource >>= diffAndRenderTermPair blobs (runBothWith replacing) (const renderSExpressionDiff)
_ -> distributeFor blobs parseSource >>= diffAndRenderTermPair blobs (runBothWith diffTerms) (const renderSExpressionDiff)
Just Language.Python -> distributeFor blobs parseSource >>= diffAndRenderTermPair blobs (runBothWith replacing) renderSExpressionDiff
_ -> distributeFor blobs parseSource >>= diffAndRenderTermPair blobs (runBothWith diffTerms) renderSExpressionDiff
IdentityDiffRenderer -> do
terms <- distributeFor blobs $ \ blob -> do
term <- parseSource blob
decorate (declarationAlgebra (source blob)) term
diffAndRenderTermPair blobs (runBothWith diffTerms) (const identity) terms
diffAndRenderTermPair blobs (runBothWith diffTerms) identity terms
where effectiveLanguage = runBothWith (<|>) (blobLanguage <$> blobs)
parseSource = parse (parserForLanguage effectiveLanguage) . source
-- | A task to diff a pair of 'Term's and render the 'Diff', producing insertion/deletion 'Patch'es for non-existent 'SourceBlob's.
diffAndRenderTermPair :: Functor f => Both SourceBlob -> Differ f a -> (Both SourceBlob -> Diff f a -> output) -> Both (Term f a) -> Task (Maybe output)
diffAndRenderTermPair :: Functor f => Both SourceBlob -> Differ f a -> (Diff f a -> output) -> Both (Term f a) -> Task (Maybe output)
diffAndRenderTermPair blobs differ renderer terms = case runJoin (nonExistentBlob <$> blobs) of
(True, True) -> pure Nothing
(_, True) -> Just <$> render (renderer blobs) (deleting (Both.fst terms))
(True, _) -> Just <$> render (renderer blobs) (inserting (Both.snd terms))
_ -> diff differ terms >>= fmap Just . render (renderer blobs)
(_, True) -> Just <$> render renderer (deleting (Both.fst terms))
(True, _) -> Just <$> render renderer (inserting (Both.snd terms))
_ -> diff differ terms >>= fmap Just . render renderer

View File

@ -29,7 +29,7 @@ spec = parallel $ do
describe "diffAndRenderTermPair" $ do
it "produces Nothing when both blobs are missing" $ do
result <- runTask (diffAndRenderTermPair (pure (emptySourceBlob "/foo")) (runBothWith replacing) (\ _ _ -> ("non-empty" :: ByteString)) (pure (cofree (() :< []))))
result <- runTask (diffAndRenderTermPair (pure (emptySourceBlob "/foo")) (runBothWith replacing) (const ("non-empty" :: ByteString)) (pure (cofree (() :< []))))
result `shouldBe` Nothing
where