1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 23:11:50 +03:00

Use alignWith diffThese instead of zipWith so we don't drop children when diffing

This commit is contained in:
joshvera 2016-07-11 15:26:08 -04:00
parent 68a14d0d74
commit 904a5ae9ea

View File

@ -69,16 +69,16 @@ run construct comparable cost algorithm = case runFree algorithm of
recur (MemberAccess a' as') (MemberAccess b' bs') = annotate $ MemberAccess (diffTerms' a' b') (diffTerms' as' bs') recur (MemberAccess a' as') (MemberAccess b' bs') = annotate $ MemberAccess (diffTerms' a' b') (diffTerms' as' bs')
recur (SubscriptAccess a' as') (SubscriptAccess b' bs') = annotate $ SubscriptAccess (diffTerms' a' b') (diffTerms' as' bs') recur (SubscriptAccess a' as') (SubscriptAccess b' bs') = annotate $ SubscriptAccess (diffTerms' a' b') (diffTerms' as' bs')
recur (MethodCall a' as' aParams') (MethodCall b' bs' bParams') = annotate $ MethodCall (diffTerms' a' b') (diffTerms' as' bs') (diffTerms' aParams' bParams') recur (MethodCall a' as' aParams') (MethodCall b' bs' bParams') = annotate $ MethodCall (diffTerms' a' b') (diffTerms' as' bs') (diffTerms' aParams' bParams')
recur (Ternary aCondition' aCases') (Ternary bCondition' bCases') = annotate $ Ternary (diffTerms' aCondition' bCondition') (zipWith diffTerms' aCases' bCases') recur (Ternary aCondition' aCases') (Ternary bCondition' bCases') = annotate $ Ternary (diffTerms' aCondition' bCondition') (alignWith diffThese aCases' bCases')
recur (Args as') (Args bs') = annotate . Args $ zipWith diffTerms' as' bs' recur (Args as') (Args bs') = annotate . Args $ alignWith diffThese as' bs'
recur (VarDecl a') (VarDecl b') = annotate . VarDecl $ diffTerms' a' b' recur (VarDecl a') (VarDecl b') = annotate . VarDecl $ diffTerms' a' b'
recur (VarAssignment a' as') (VarAssignment b' bs') = annotate $ VarAssignment (diffTerms' a' b') (diffTerms' as' bs') recur (VarAssignment a' as') (VarAssignment b' bs') = annotate $ VarAssignment (diffTerms' a' b') (diffTerms' as' bs')
recur (Operator a') (Operator b') = annotate $ Operator (zipWith diffTerms' a' b') recur (Operator a') (Operator b') = annotate $ Operator (alignWith diffThese a' b')
recur (Switch a' as') (Switch b' bs') = annotate $ Switch (diffTerms' a' b') (alignWith (these (pure . Delete) (pure . Insert) diffTerms') as' bs') recur (Switch a' as') (Switch b' bs') = annotate $ Switch (diffTerms' a' b') (alignWith (these (pure . Delete) (pure . Insert) diffTerms') as' bs')
recur (Case a' as') (Case b' bs') = annotate $ Case (diffTerms' a' b') (diffTerms' as' bs') recur (Case a' as') (Case b' bs') = annotate $ Case (diffTerms' a' b') (diffTerms' as' bs')
recur (Object as') (Object bs') = annotate $ Object (zipWith diffTerms' as' bs') recur (Object as') (Object bs') = annotate $ Object (alignWith diffThese as' bs')
recur (Pair a1 a2) (Pair b1 b2) = annotate $ Pair (diffTerms' a1 b1) (diffTerms' a2 b2) recur (Pair a1 a2) (Pair b1 b2) = annotate $ Pair (diffTerms' a1 b1) (diffTerms' a2 b2)
recur (Commented a1 a2) (Commented b1 b2) = annotate $ Commented (zipWith diffTerms' a1 b1) (diffTerms' <$> a2 <*> b2) recur (Commented a1 a2) (Commented b1 b2) = annotate $ Commented (alignWith diffThese a1 b1) (diffTerms' <$> a2 <*> b2)
recur (Comment _) (Comment _) = pure $ Replace (cofree (annotation1 :< a)) (cofree (annotation2 :< b)) recur (Comment _) (Comment _) = pure $ Replace (cofree (annotation1 :< a)) (cofree (annotation2 :< b))
recur (Leaf _) (Leaf _) = pure $ Replace (cofree (annotation1 :< a)) (cofree (annotation2 :< b)) recur (Leaf _) (Leaf _) = pure $ Replace (cofree (annotation1 :< a)) (cofree (annotation2 :< b))
recur _ _ = pure $ Replace (cofree (annotation1 :< a)) (cofree (annotation2 :< b)) recur _ _ = pure $ Replace (cofree (annotation1 :< a)) (cofree (annotation2 :< b))