1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 12:51:52 +03:00

Merge pull request #727 from github/comma-summaries

Comma summaries
This commit is contained in:
Rick Winfrey 2016-08-17 08:19:56 -05:00 committed by GitHub
commit 1d79153f01
6 changed files with 11 additions and 3 deletions

View File

@ -76,6 +76,8 @@ data Category
| Case
-- | An expression with an operator.
| Operator
-- | An comma operator expression
| CommaOperator
-- | An object/dictionary/hash literal.
| Object
-- | A throw statement.

View File

@ -57,7 +57,7 @@ summaries (Replace i1 i2) = zipWith (\a b -> "Replaced" <+> "the" <+> a <+> "wit
toLeafInfos :: DiffInfo -> [Doc]
toLeafInfos LeafInfo{..} = pure $ squotes (toDoc termName) <+> (toDoc categoryName)
toLeafInfos BranchInfo{..} = pretty <$> branches
toLeafInfos BranchInfo{..} = toLeafInfos =<< branches
toLeafInfos err@ErrorInfo{} = pure $ pretty err
toTermName :: (HasCategory leaf, HasField fields Category, HasField fields Range) => Source Char -> Term leaf (Record fields) -> Text
@ -214,6 +214,7 @@ instance HasCategory Category where
C.Class -> "class"
C.Method -> "method"
C.If -> "if statement"
C.CommaOperator -> "comma operator"
instance (HasCategory leaf, HasField fields Category) => HasCategory (Term leaf (Record fields)) where
toCategoryName = toCategoryName . category . extract

View File

@ -55,6 +55,9 @@ termConstructor source sourceSpan info = fmap cofree . construct
(base:element:[]) -> withDefaultInfo $ S.SubscriptAccess base element
_ -> errorWith children
construct children | isOperator (category info) = withDefaultInfo $ S.Operator children
construct children | CommaOperator == category info = withDefaultInfo $ case children of
[child, rest] | S.Indexed cs <- unwrap rest -> S.Indexed $ child : toList cs
_ -> S.Indexed children
construct children | Function == category info = case children of
(body:[]) -> withDefaultInfo $ S.Function Nothing Nothing body
(params:body:[]) | (info :< _) <- runCofree params, Params == category info ->

View File

@ -24,10 +24,12 @@ concatOutputs l = T.intercalate "\n" (toText <$> l)
toSeries :: Output -> Series
toSeries (JSONOutput series) = series
toSeries (SummaryOutput series) = series
toSeries _ = mempty
toText :: Output -> Text
toText (SplitOutput text) = text
toText (PatchOutput text) = text
toText _ = mempty
-- | The available types of diff rendering.

View File

@ -42,7 +42,7 @@ categoriesForLanguage language name = case (language, name) of
(JavaScript, "bool_op") -> BinaryOperator -- boolean operator, e.g. ||, &&.
(JavaScript, "bitwise_op") -> BinaryOperator -- bitwise operator, e.g. ^, &, etc.
(JavaScript, "rel_op") -> BinaryOperator -- relational operator, e.g. >, <, <=, >=, ==, !=.
(JavaScript, "comma_op") -> Operator -- comma operator, e.g. expr1, expr2.
(JavaScript, "comma_op") -> CommaOperator -- comma operator, e.g. expr1, expr2.
(JavaScript, "delete_op") -> Operator -- delete operator, e.g. delete x[2].
(JavaScript, "type_op") -> Operator -- type operator, e.g. typeof Object.
(JavaScript, "void_op") -> Operator -- void operator, e.g. void 2.

@ -1 +1 @@
Subproject commit 3af143b53c8f9a2a6761d8e9ea91d47982cc3bc0
Subproject commit 45875c177feba7e9c25f780669e6719c59441a42