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:
parent
f3d99dc300
commit
cc94e45436
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user