1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Remove description from diff summary

This commit is contained in:
joshvera 2016-05-17 15:59:07 -04:00
parent 4d6427a24e
commit 68f5b0f669
3 changed files with 44 additions and 19 deletions

View File

@ -5,9 +5,10 @@ import Prelude hiding (fst, snd)
import Diff
import Info
import Patch
import Term
import Syntax
import Category
import Data.Maybe (listToMaybe)
import Data.Maybe (fromMaybe)
import Data.Set (toList)
import Control.Comonad.Trans.Cofree
import Control.Monad.Trans.Free
@ -15,10 +16,9 @@ import Control.Monad
import Data.Functor.Foldable as Foldable
import qualified Data.Foldable as F
data DiffInfo = DiffInfo deriving (Eq)
data DiffInfo = DiffInfo { termName :: String } deriving (Eq)
data DiffSummary a = DiffSummary {
description :: String,
patch :: Patch DiffInfo,
parentAnnotations :: [a]
} deriving (Eq, Functor)
@ -26,27 +26,29 @@ data DiffSummary a = DiffSummary {
instance Show a => Show (DiffSummary a) where
show diffSummary = case patch diffSummary of
(Replace _ _) -> "Replaced "
(Insert term) -> "Added "
(Delete term) -> "Deleted "
(Insert termInfo) -> "Added " ++ show (termName termInfo)
(Delete termInfo) -> "Deleted "
diffSummary :: Diff leaf Info -> [DiffSummary ()]
diffSummary :: Show leaf => Diff leaf Info -> [DiffSummary ()]
diffSummary = cata diffSummary' where
diffSummary' :: DiffF leaf Info [DiffSummary ()] -> [DiffSummary ()]
diffSummary' :: Show leaf => DiffF leaf Info [DiffSummary ()] -> [DiffSummary ()]
diffSummary' (Free (_ :< Leaf _)) = [] -- Skip leaves since they don't have any changes
diffSummary' (Free (_ :< Indexed children)) = prependSummary () <$> join children
diffSummary' (Free (_ :< Fixed children)) = prependSummary () <$> join children
diffSummary' (Free (_ :< Keyed children)) = prependSummary () <$> join (F.toList children)
diffSummary' (Pure (Insert _)) = [DiffSummary "insert" (Insert DiffInfo) []]
diffSummary' (Pure (Delete _)) = [DiffSummary "delete" (Delete DiffInfo) []]
diffSummary' (Pure (Replace _ _)) = [DiffSummary "delete" (Replace DiffInfo DiffInfo) []]
diffSummary' (Pure (Insert term)) = [DiffSummary (Insert (DiffInfo (toTermName term))) []]
diffSummary' (Pure (Delete term)) = [DiffSummary (Delete (DiffInfo (toTermName term))) []]
diffSummary' (Pure (Replace t1 t2)) = [DiffSummary (Replace (DiffInfo (toTermName t1)) (DiffInfo (toTermName t2))) []]
prependSummary :: a -> DiffSummary a -> DiffSummary a
prependSummary annotation summary = summary { parentAnnotations = annotation : parentAnnotations summary }
maybeFirstCategory :: (Categorizable a) => a -> Maybe Category
maybeFirstCategory term = listToMaybe . toList $ Category.categories term
toTermName :: Show leaf => Term leaf Info -> String
toTermName term = case runCofree term of
(_ :< (Leaf leaf)) -> show leaf
(info :< Indexed _) -> show $ toCategory info
(info :< Fixed _) -> show $ toCategory info
(info :< Keyed _) -> show $ toCategory info
toCategory :: Info -> a -> DiffSummary a
toCategory info a = case maybeFirstCategory info of
Just category -> undefined
Nothing -> undefined
toCategory :: Info -> Category
toCategory info = fromMaybe (Other "Unknown") (maybeFirstCategory info)

View File

@ -1,5 +1,6 @@
module Info where
import Data.Maybe (listToMaybe)
import Category
import Data.Set
import Range
@ -11,3 +12,6 @@ data Info = Info { characterRange :: !Range, categories :: !(Set Category), size
instance Categorizable Info where
categories = Info.categories
maybeFirstCategory :: (Categorizable a) => a -> Maybe Category
maybeFirstCategory term = listToMaybe . toList $ Category.categories term

View File

@ -1,15 +1,34 @@
module DiffSummarySpec where
import Test.Hspec
import Diff
import Info
import Syntax
import Control.Comonad.Trans.Cofree
import Control.Monad.Trans.Free
import Patch
import Range
import Category
import Data.Set
import DiffSummary
testSummary :: DiffSummary String
testSummary = DiffSummary { description = "lol", patch = Insert DiffInfo, parentAnnotations = [] }
arrayInfo :: Info
arrayInfo = Info (rangeAt 0) (singleton ArrayLiteral) 2
literalInfo :: Info
literalInfo = Info (rangeAt 1) (singleton StringLiteral) 1
testDiff :: Diff String Info
testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree $ literalInfo :< Leaf "a")) ])
testSummary :: DiffSummary Char
testSummary = DiffSummary { patch = Insert (DiffInfo "a"), parentAnnotations = [] }
spec :: Spec
spec = parallel $ do
describe "diffSummary" $ do
it "outputs a diff summary" $ do
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "a"), parentAnnotations = [()] } ]
describe "show" $ do
it "should print adds" $
show testSummary `shouldBe` "Added an 'a' expression"