mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Merge remote-tracking branch 'origin/master' into error-syntax
This commit is contained in:
commit
fbc9e335a3
@ -70,6 +70,8 @@ data Category
|
||||
| Operator
|
||||
-- | An object/dictionary/hash literal.
|
||||
| Object
|
||||
-- | A return statement.
|
||||
| Return
|
||||
-- | A non-standard category, which can be used for comparability.
|
||||
| Other Text
|
||||
deriving (Eq, Generic, Ord, Show)
|
||||
|
@ -60,6 +60,7 @@ toTermName term = case unwrap term of
|
||||
S.Operator syntaxes -> mconcat $ toTermName <$> syntaxes
|
||||
S.Object kvs -> "{" <> intercalate ", " (toTermName <$> kvs) <> "}"
|
||||
S.Pair a b -> toTermName a <> ": " <> toTermName b
|
||||
S.Return expr -> maybe "empty" toTermName expr
|
||||
Comment a -> toCategoryName a
|
||||
|
||||
class HasCategory a where
|
||||
@ -100,7 +101,12 @@ instance HasCategory Category where
|
||||
StringLiteral -> "string"
|
||||
SymbolLiteral -> "symbol"
|
||||
TemplateString -> "template string"
|
||||
<<<<<<< HEAD
|
||||
C.Object -> "object"
|
||||
=======
|
||||
Category.Object -> "object"
|
||||
Category.Return -> "return statement"
|
||||
>>>>>>> origin/master
|
||||
|
||||
instance (HasCategory leaf, HasField fields Category) => HasCategory (Term leaf (Record fields)) where
|
||||
toCategoryName = toCategoryName . category . extract
|
||||
@ -148,6 +154,7 @@ diffSummary :: (HasCategory leaf, HasField fields Category, HasField fields Sour
|
||||
diffSummary = cata $ \case
|
||||
-- Skip comments and leaves since they don't have any changes
|
||||
(Free (_ :< Leaf _)) -> []
|
||||
<<<<<<< HEAD
|
||||
Free (_ :< (S.Comment _)) -> []
|
||||
(Free (infos :< S.Indexed children)) -> prependSummary (category $ snd infos) <$> join children
|
||||
(Free (infos :< S.Fixed children)) -> prependSummary (category $ snd infos) <$> join children
|
||||
@ -169,6 +176,29 @@ diffSummary = cata $ \case
|
||||
Free (infos :< (S.Pair a b)) -> prependSummary (category $ snd infos) <$> a <> b
|
||||
Free (infos :< (S.Commented cs leaf)) -> prependSummary (category $ snd infos) <$> join cs <> fromMaybe [] leaf
|
||||
Free (infos :< (S.Error children)) -> prependSummary (category $ snd infos) <$> join children
|
||||
=======
|
||||
Free (_ :< (Syntax.Comment _)) -> []
|
||||
(Free (infos :< Syntax.Indexed children)) -> prependSummary (category $ snd infos) <$> join children
|
||||
(Free (infos :< Syntax.Fixed children)) -> prependSummary (category $ snd infos) <$> join children
|
||||
(Free (infos :< Syntax.FunctionCall identifier children)) -> prependSummary (category $ snd infos) <$> join (Prologue.toList (identifier : children))
|
||||
(Free (infos :< Syntax.Function id ps body)) -> prependSummary (category $ snd infos) <$> (fromMaybe [] id) <> (fromMaybe [] ps) <> body
|
||||
(Free (infos :< Syntax.Assignment id value)) -> prependSummary (category $ snd infos) <$> id <> value
|
||||
(Free (infos :< Syntax.MemberAccess base property)) -> prependSummary (category $ snd infos) <$> base <> property
|
||||
(Free (infos :< Syntax.SubscriptAccess base property)) -> prependSummary (category $ snd infos) <$> base <> property
|
||||
(Free (infos :< Syntax.MethodCall targetId methodId ps)) -> prependSummary (category $ snd infos) <$> targetId <> methodId <> ps
|
||||
(Free (infos :< Syntax.VarAssignment varId value)) -> prependSummary (category $ snd infos) <$> varId <> value
|
||||
(Free (infos :< Syntax.VarDecl decl)) -> prependSummary (category $ snd infos) <$> decl
|
||||
(Free (infos :< Syntax.Args args)) -> prependSummary (category $ snd infos) <$> join args
|
||||
(Free (infos :< Syntax.Switch expr cases)) -> prependSummary (category $ snd infos) <$> expr <> join cases
|
||||
(Free (infos :< Syntax.Case expr body)) -> prependSummary (category $ snd infos) <$> expr <> body
|
||||
Free (infos :< (Syntax.Ternary expr cases)) -> prependSummary (category $ snd infos) <$> expr <> join cases
|
||||
Free (infos :< (Syntax.MathAssignment id value)) -> prependSummary (category $ snd infos) <$> id <> value
|
||||
Free (infos :< (Syntax.Operator syntaxes)) -> prependSummary (category $ snd infos) <$> join syntaxes
|
||||
Free (infos :< (Syntax.Object kvs)) -> prependSummary (category $ snd infos) <$> join kvs
|
||||
Free (infos :< (Syntax.Pair a b)) -> prependSummary (category $ snd infos) <$> a <> b
|
||||
Free (infos :< (Syntax.Return expr)) -> prependSummary (category $ snd infos) <$> fromMaybe [] expr
|
||||
Free (infos :< (Syntax.Commented cs leaf)) -> prependSummary (category $ snd infos) <$> join cs <> fromMaybe [] leaf
|
||||
>>>>>>> origin/master
|
||||
(Pure (Insert term)) -> [ DiffSummary (Insert $ termToDiffInfo term) [] ]
|
||||
(Pure (Delete term)) -> [ DiffSummary (Delete $ termToDiffInfo term) [] ]
|
||||
(Pure (Replace t1 t2)) -> [ DiffSummary (Replace (termToDiffInfo t1) (termToDiffInfo t2)) [] ]
|
||||
|
@ -32,7 +32,11 @@ termConstructor source info = cofree . construct
|
||||
where
|
||||
withDefaultInfo syntax = (info :< syntax)
|
||||
construct :: (Show (Record fields), HasField fields Category, HasField fields Range) => [Term Text (Record fields)] -> CofreeF (S.Syntax Text) (Record fields) (Term Text (Record fields))
|
||||
construct [] = withDefaultInfo . S.Leaf . pack . toString $ slice (characterRange info) source
|
||||
construct [] = case category info of
|
||||
Return -> withDefaultInfo $ S.Return Nothing -- Map empty return statements to Return Nothing
|
||||
_ -> withDefaultInfo . S.Leaf . pack . toString $ slice (characterRange info) source
|
||||
construct children | Return == category info =
|
||||
withDefaultInfo $ S.Return (listToMaybe children)
|
||||
construct children | Assignment == category info = case children of
|
||||
(identifier:value:[]) -> withDefaultInfo $ S.Assignment identifier value
|
||||
children -> withDefaultInfo $ S.Error children
|
||||
|
@ -83,6 +83,7 @@ termFields info syntax = "range" .= characterRange info : "category" .= category
|
||||
S.SubscriptAccess id property -> [ "subscriptId" .= id ] <> [ "property" .= property ]
|
||||
S.Object pairs -> childrenFields pairs
|
||||
S.Pair a b -> childrenFields [a, b]
|
||||
S.Return expr -> [ "returnExpr" .= expr ]
|
||||
S.Comment _ -> []
|
||||
S.Commented comments child -> childrenFields (comments <> maybeToList child)
|
||||
S.Error c -> childrenFields c
|
||||
|
@ -62,6 +62,7 @@ styleName category = "category-" <> case category of
|
||||
C.Ternary -> "ternary"
|
||||
C.Operator -> "operator"
|
||||
C.Object -> "object"
|
||||
C.Return -> "return_statement"
|
||||
Other string -> string
|
||||
|
||||
-- | Pick the class name for a split patch.
|
||||
|
@ -52,6 +52,7 @@ data Syntax
|
||||
| Comment a
|
||||
| Commented [f] (Maybe f)
|
||||
| Error [f]
|
||||
| Return (Maybe f)
|
||||
deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable)
|
||||
|
||||
|
||||
|
@ -76,6 +76,7 @@ defaultCategoryForNodeName name = case name of
|
||||
"true" -> Boolean
|
||||
"false" -> Boolean
|
||||
"ternary" -> Ternary
|
||||
"return_statement" -> Return
|
||||
_ -> Other name
|
||||
|
||||
-- | Return a parser for a tree sitter language & document.
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 6cd5009c55addfb95f823c2c2b9be805e8dc68f8
|
||||
Subproject commit 0989485a6fad0ac82c12410c6ae6c9d5453662a2
|
Loading…
Reference in New Issue
Block a user