From 5d8cfe826dce032efee2c1dcbf161d11bf60fea7 Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 18 Aug 2016 09:58:23 -0400 Subject: [PATCH 1/5] Prefix errors with Error: --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index c38da5ccb..393e117a6 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -232,4 +232,4 @@ instance (Eq a, Arbitrary a) => Arbitrary (DiffSummary a) where instance P.Pretty DiffInfo where pretty LeafInfo{..} = squotes (string $ toSL termName) <+> (string $ toSL categoryName) pretty BranchInfo{..} = mconcat $ punctuate (string "," <> space) (pretty <$> branches) - pretty ErrorInfo{..} = squotes (string $ toSL termName) <+> "at" <+> (string . toSL $ displayStartEndPos errorSpan) <+> "in" <+> (string . toSL $ spanName errorSpan) + pretty ErrorInfo{..} = "Error:" <+> squotes (string $ toSL termName) <+> "at" <+> (string . toSL $ displayStartEndPos errorSpan) <+> "in" <+> (string . toSL $ spanName errorSpan) From b6cf282d2b982ad0da1bc2c851b01bc2c4655b19 Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 18 Aug 2016 10:27:07 -0400 Subject: [PATCH 2/5] Move Error doc calculation to summaries --- src/DiffSummary.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 393e117a6..e3cc9a41c 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -21,6 +21,7 @@ import Text.PrettyPrint.Leijen.Text ((<+>), squotes, space, string, Doc, punctua import qualified Text.PrettyPrint.Leijen.Text as P import SourceSpan import Source +import Data.Text.Lazy (toLower) data DiffInfo = LeafInfo { categoryName :: Text, termName :: Text } | BranchInfo { branches :: [ DiffInfo ], categoryName :: Text, branchType :: Branch } @@ -51,9 +52,15 @@ diffSummaries sources = para $ \diff -> summaries :: Patch DiffInfo -> [P.Doc] -summaries (Insert info) = (("Added" <+> "the") <+>) <$> toLeafInfos info -summaries (Delete info) = (("Deleted" <+> "the") <+>) <$> toLeafInfos info -summaries (Replace i1 i2) = zipWith (\a b -> "Replaced" <+> "the" <+> a <+> "with the" <+> b) (toLeafInfos i1) (toLeafInfos i2) +summaries (Insert info) = prefixOrErrorDoc "Added" info <$> toLeafInfos info +summaries (Delete info) = prefixOrErrorDoc "Deleted" info <$> toLeafInfos info +summaries (Replace i1 i2) = zipWith (\a b -> prefixOrErrorDoc "Replaced" i1 a <+> "with the" <+> b) (toLeafInfos i1) (toLeafInfos i2) + +prefixOrErrorDoc :: Text -> DiffInfo -> Doc -> Doc +prefixOrErrorDoc prefix info doc = message <+> "the" <+> doc + where message = case info of + ErrorInfo{} -> "Error:" <+> string (toLower $ toSL prefix) + _ -> string $ toSL prefix toLeafInfos :: DiffInfo -> [Doc] toLeafInfos LeafInfo{..} = pure $ squotes (toDoc termName) <+> (toDoc categoryName) @@ -232,4 +239,4 @@ instance (Eq a, Arbitrary a) => Arbitrary (DiffSummary a) where instance P.Pretty DiffInfo where pretty LeafInfo{..} = squotes (string $ toSL termName) <+> (string $ toSL categoryName) pretty BranchInfo{..} = mconcat $ punctuate (string "," <> space) (pretty <$> branches) - pretty ErrorInfo{..} = "Error:" <+> squotes (string $ toSL termName) <+> "at" <+> (string . toSL $ displayStartEndPos errorSpan) <+> "in" <+> (string . toSL $ spanName errorSpan) + pretty ErrorInfo{..} = squotes (string $ toSL termName) <+> "at" <+> (string . toSL $ displayStartEndPos errorSpan) <+> "in" <+> (string . toSL $ spanName errorSpan) From fbb108d7a1327dea7a5356dd0f5612efd6d35a2a Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 18 Aug 2016 11:05:28 -0400 Subject: [PATCH 3/5] Don't use toLower --- src/DiffSummary.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index e3cc9a41c..cb49fa210 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -21,7 +21,6 @@ import Text.PrettyPrint.Leijen.Text ((<+>), squotes, space, string, Doc, punctua import qualified Text.PrettyPrint.Leijen.Text as P import SourceSpan import Source -import Data.Text.Lazy (toLower) data DiffInfo = LeafInfo { categoryName :: Text, termName :: Text } | BranchInfo { branches :: [ DiffInfo ], categoryName :: Text, branchType :: Branch } @@ -57,10 +56,10 @@ summaries (Delete info) = prefixOrErrorDoc "Deleted" info <$> toLeafInfos info summaries (Replace i1 i2) = zipWith (\a b -> prefixOrErrorDoc "Replaced" i1 a <+> "with the" <+> b) (toLeafInfos i1) (toLeafInfos i2) prefixOrErrorDoc :: Text -> DiffInfo -> Doc -> Doc -prefixOrErrorDoc prefix info doc = message <+> "the" <+> doc +prefixOrErrorDoc prefix info doc = message <+> string (toSL prefix) <+> "the" <+> doc where message = case info of - ErrorInfo{} -> "Error:" <+> string (toLower $ toSL prefix) - _ -> string $ toSL prefix + ErrorInfo{} -> "Error:" + _ -> mempty toLeafInfos :: DiffInfo -> [Doc] toLeafInfos LeafInfo{..} = pure $ squotes (toDoc termName) <+> (toDoc categoryName) From 6d290883368ee51123d5f3b8fce1bd8f6b38ed74 Mon Sep 17 00:00:00 2001 From: joshvera Date: Thu, 18 Aug 2016 11:20:18 -0400 Subject: [PATCH 4/5] Update test cases --- src/DiffSummary.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index cb49fa210..a131e4a97 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -51,9 +51,9 @@ diffSummaries sources = para $ \diff -> summaries :: Patch DiffInfo -> [P.Doc] -summaries (Insert info) = prefixOrErrorDoc "Added" info <$> toLeafInfos info -summaries (Delete info) = prefixOrErrorDoc "Deleted" info <$> toLeafInfos info -summaries (Replace i1 i2) = zipWith (\a b -> prefixOrErrorDoc "Replaced" i1 a <+> "with the" <+> b) (toLeafInfos i1) (toLeafInfos i2) +summaries (Insert info) = uncurry (prefixOrErrorDoc "Added") <$> toLeafInfos info +summaries (Delete info) = uncurry (prefixOrErrorDoc "Deleted") <$> toLeafInfos info +summaries (Replace i1 i2) = zipWith (\a b -> uncurry (prefixOrErrorDoc "Replaced") a <+> "with the" <+> snd b) (toLeafInfos i1) (toLeafInfos i2) prefixOrErrorDoc :: Text -> DiffInfo -> Doc -> Doc prefixOrErrorDoc prefix info doc = message <+> string (toSL prefix) <+> "the" <+> doc @@ -61,10 +61,10 @@ prefixOrErrorDoc prefix info doc = message <+> string (toSL prefix) <+> "the" <+ ErrorInfo{} -> "Error:" _ -> mempty -toLeafInfos :: DiffInfo -> [Doc] -toLeafInfos LeafInfo{..} = pure $ squotes (toDoc termName) <+> (toDoc categoryName) +toLeafInfos :: DiffInfo -> [(DiffInfo, Doc)] +toLeafInfos info@LeafInfo{..} = pure (info, squotes (toDoc termName) <+> (toDoc categoryName)) toLeafInfos BranchInfo{..} = toLeafInfos =<< branches -toLeafInfos err@ErrorInfo{} = pure $ pretty err +toLeafInfos err@ErrorInfo{} = pure (err, pretty err) toTermName :: (HasCategory leaf, HasField fields Category, HasField fields Range) => Source Char -> Term leaf (Record fields) -> Text toTermName source term = case unwrap term of From 795fce207348866ba685667d3633a42d2ee9275f Mon Sep 17 00:00:00 2001 From: joshvera Date: Mon, 22 Aug 2016 13:50:47 -0400 Subject: [PATCH 5/5] s/Error/Diff Summary Error --- src/DiffSummary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index a131e4a97..30df01ebd 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -58,7 +58,7 @@ summaries (Replace i1 i2) = zipWith (\a b -> uncurry (prefixOrErrorDoc "Replaced prefixOrErrorDoc :: Text -> DiffInfo -> Doc -> Doc prefixOrErrorDoc prefix info doc = message <+> string (toSL prefix) <+> "the" <+> doc where message = case info of - ErrorInfo{} -> "Error:" + ErrorInfo{} -> "Diff Summary Error:" _ -> mempty toLeafInfos :: DiffInfo -> [(DiffInfo, Doc)]