mirror of
https://github.com/github/semantic.git
synced 2024-12-01 00:33:59 +03:00
++tree-sitter-ruby and parse singleton methods to fix ambiguity
This commit is contained in:
parent
1bd36fff7c
commit
a10bc515c0
2
languages/ruby/vendor/tree-sitter-ruby
vendored
2
languages/ruby/vendor/tree-sitter-ruby
vendored
@ -1 +1 @@
|
||||
Subproject commit b2ca35ffc5b1e3eec5ee41fc3d0420788dffa04a
|
||||
Subproject commit 8b3d08a3818610c5111bfc87250446b1e65fe0f0
|
@ -225,6 +225,8 @@ data Category
|
||||
| RuneLiteral
|
||||
-- | A modifier version of another Category, e.g. Ruby’s trailing @if@, @while@, etc. terms, whose subterms are swapped relative to regular @if@, @while@, etc. terms.
|
||||
| Modifier Category
|
||||
-- | A singleton method declaration, e.g. `def self.foo;end` in Ruby
|
||||
| SingletonMethod
|
||||
deriving (Eq, Generic, Ord, Show)
|
||||
|
||||
{-# DEPRECATED RescueModifier "Deprecated; use Modifier Rescue instead." #-}
|
||||
@ -353,4 +355,5 @@ instance Listable Category where
|
||||
, FieldDeclarations
|
||||
, RuneLiteral
|
||||
, Modifier If
|
||||
, SingletonMethod
|
||||
] ++ concat (mapT (Other . unListableText) tiers)
|
||||
|
@ -293,6 +293,7 @@ parentContexts contexts = hsep $ either identifiableDoc annotatableDoc <$> conte
|
||||
C.Else -> "in an" <+> catName c
|
||||
C.Elsif -> "in the" <+> squotes (termName t) <+> catName c
|
||||
C.Method -> "in the" <+> squotes (termName t) <+> catName c
|
||||
C.SingletonMethod -> "in the" <+> squotes (termName t) <+> catName c
|
||||
C.Ternary -> "in the" <+> squotes (termName t) <+> catName c
|
||||
C.Ensure -> "in an" <+> catName c
|
||||
C.Rescue -> case t of
|
||||
@ -460,6 +461,7 @@ instance HasCategory Category where
|
||||
C.Constant -> "constant"
|
||||
C.Superclass -> "superclass"
|
||||
C.SingletonClass -> "singleton class"
|
||||
C.SingletonMethod -> "method"
|
||||
C.RangeExpression -> "range"
|
||||
C.ScopeOperator -> "scope operator"
|
||||
C.BeginBlock -> "BEGIN block"
|
||||
|
@ -65,7 +65,7 @@ termAssignment _ category children
|
||||
(For, lhs : expr : rest ) -> Just $ S.For [lhs, expr] rest
|
||||
(OperatorAssignment, [ identifier, value ]) -> Just $ S.OperatorAssignment identifier value
|
||||
(MemberAccess, [ base, property ]) -> Just $ S.MemberAccess base property
|
||||
(Method, expr : methodName : rest)
|
||||
(SingletonMethod, expr : methodName : rest)
|
||||
| params : body <- rest
|
||||
, Params <- Info.category (extract params)
|
||||
-> Just $ S.Method methodName (Just expr) Nothing (toList (unwrap params)) body
|
||||
@ -153,6 +153,7 @@ categoryForRubyName = \case
|
||||
"scope_resolution" -> ScopeOperator
|
||||
"self" -> Identifier
|
||||
"singleton_class" -> SingletonClass
|
||||
"singleton_method" -> SingletonMethod
|
||||
"splat_parameter" -> SplatParameter
|
||||
"string" -> StringLiteral
|
||||
"subshell" -> Subshell
|
||||
|
@ -126,6 +126,7 @@ styleName category = "category-" <> case category of
|
||||
C.Constant -> "constant"
|
||||
C.Superclass -> "superclass"
|
||||
C.SingletonClass -> "singleton_class"
|
||||
C.SingletonMethod -> "singleton_method"
|
||||
C.RangeExpression -> "range"
|
||||
C.ScopeOperator -> "scope_operator"
|
||||
C.BeginBlock -> "begin_block"
|
||||
|
@ -105,6 +105,7 @@ toTOCSummaries patch = case afterOrBefore patch of
|
||||
LeafInfo{..} -> pure . TOCSummary patch' $ case leafCategory of
|
||||
C.Function -> Summarizable leafCategory termName leafSourceSpan (patchType patch')
|
||||
C.Method -> Summarizable leafCategory termName leafSourceSpan (patchType patch')
|
||||
C.SingletonMethod -> Summarizable leafCategory termName leafSourceSpan (patchType patch')
|
||||
_ -> NotSummarizable
|
||||
|
||||
flattenPatch :: Patch DiffInfo -> [Patch DiffInfo]
|
||||
|
@ -34,7 +34,7 @@ spec = parallel $ do
|
||||
sourceBlobs <- blobsForPaths (both "ruby/methods.A.rb" "ruby/methods.B.rb")
|
||||
diff <- testDiff sourceBlobs
|
||||
diffTOC sourceBlobs diff `shouldBe`
|
||||
[ JSONSummary $ Summarizable C.Method "self.foo" (sourceSpanBetween (1, 1) (2, 4)) "added"
|
||||
[ JSONSummary $ Summarizable C.SingletonMethod "self.foo" (sourceSpanBetween (1, 1) (2, 4)) "added"
|
||||
, JSONSummary $ InSummarizable C.Method "bar" (sourceSpanBetween (4, 1) (6, 4))
|
||||
, JSONSummary $ Summarizable C.Method "baz" (sourceSpanBetween (4, 1) (5, 4)) "removed" ]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user