From 3815e713b5ea3913b964eb762a5d9665c5d66171 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 12 Oct 2016 14:21:25 -0700 Subject: [PATCH] Capture comments and hide them for summaries only --- src/DiffSummary.hs | 5 ++++- src/Language/JavaScript.hs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index 9d76c0e89..61ccfb02e 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -69,6 +69,7 @@ isErrorSummary _ = False data DiffInfo = LeafInfo { categoryName :: Text, termName :: Text, sourceSpan :: SourceSpan } | BranchInfo { branches :: [ DiffInfo ], categoryName :: Text, branchType :: Branch } | ErrorInfo { errorSpan :: SourceSpan, termName :: Text } + | HideInfo deriving (Eq, Show) data Branch = BIndexed | BFixed | BCommented deriving (Show, Eq, Generic) @@ -146,6 +147,7 @@ determiner _ = "the" toLeafInfos :: DiffInfo -> [JSONSummary Doc SourceSpan] toLeafInfos err@ErrorInfo{..} = pure $ ErrorSummary (pretty err) errorSpan toLeafInfos BranchInfo{..} = branches >>= toLeafInfos +toLeafInfos HideInfo = [] toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of (LeafInfo "number" termName _) -> squotes $ toDoc termName (LeafInfo "boolean" termName _) -> squotes $ toDoc termName @@ -241,7 +243,7 @@ termToDiffInfo blob term = case unwrap term of S.Indexed children -> BranchInfo (termToDiffInfo' <$> children) (toCategoryName term) BIndexed S.Fixed children -> BranchInfo (termToDiffInfo' <$> children) (toCategoryName term) BFixed S.AnonymousFunction _ _ -> LeafInfo "anonymous function" (toTermName' term) (getField $ extract term) - Commented cs leaf -> BranchInfo (termToDiffInfo' <$> cs <> maybeToList leaf) (toCategoryName term) BCommented + S.Comment _ -> HideInfo S.Error _ -> ErrorInfo (getField $ extract term) (toTermName' term) _ -> LeafInfo (toCategoryName term) (toTermName' term) (getField $ extract term) where toTermName' = toTermName blob @@ -346,3 +348,4 @@ instance P.Pretty DiffInfo where pretty LeafInfo{..} = squotes (string $ toSL termName) <+> string (toSL categoryName) pretty BranchInfo{..} = mconcat $ punctuate (string "," P.<> space) (pretty <$> branches) pretty ErrorInfo{..} = squotes (string $ toSL termName) <+> "at" <+> (string . toSL $ displayStartEndPos errorSpan) + pretty HideInfo = "" diff --git a/src/Language/JavaScript.hs b/src/Language/JavaScript.hs index 0f3c7e9a9..54f261295 100644 --- a/src/Language/JavaScript.hs +++ b/src/Language/JavaScript.hs @@ -49,6 +49,7 @@ termConstructor source sourceSpan name range children ("case", [ expr, body ]) -> S.Case expr body ("object", _) -> S.Object $ foldMap toTuple children ("pair", _) -> S.Fixed children + ("comment", _) -> S.Comment . toText $ slice range source ("if_statement", [ expr, clause1, clause2 ]) -> S.If expr clause1 (Just clause2) ("if_statement", [ expr, clause ]) -> S.If expr clause Nothing ("while_statement", [ expr, body ]) -> S.While expr body