1
1
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:
Timothy Clem 2017-02-17 11:34:47 -08:00
parent 1bd36fff7c
commit a10bc515c0
7 changed files with 11 additions and 3 deletions

@ -1 +1 @@
Subproject commit b2ca35ffc5b1e3eec5ee41fc3d0420788dffa04a
Subproject commit 8b3d08a3818610c5111bfc87250446b1e65fe0f0

View File

@ -225,6 +225,8 @@ data Category
| RuneLiteral
-- | A modifier version of another Category, e.g. Rubys 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)

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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]

View File

@ -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" ]