Skip to content

Commit

Permalink
Add test and update tree-sitter query for Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Bennett-Lovesey committed Aug 8, 2023
1 parent 9c02313 commit eee1f30
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 3 deletions.
243 changes: 243 additions & 0 deletions goldens/test.rb.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
Name: require
Reference (reference.call):
require "net/http"

Name: SomeClass
Declaration (definition.class):
class SomeClass
def nice()
"Nice"
end
end

Name: SomeClass
Reference (reference.call):
SomeClass

Name: nice
Reference (reference.call):
nice

Name: nice
Parameters: ()
Definition (definition.method):
def nice()
"Nice"
end
Lineage: [SomeClass]
Lineage types: [class]

Name: Foo
Definition (definition.module):
module Foo
def foo
:foo
end
end

Name: Foo
Reference (reference.call):
Foo

Name: foo
Reference (reference.call):
foo

Name: Test
Reference (reference.call):
Test

Name: SubTest
Definition (definition.module):
module Test::SubTest
class MyClass < SomeClass
include Foo

def self.foo
new.foo
end

class << self
def bar
new.bar(true)
end
end

def foo
self
end

def bar(arg1, arg2 = "fine")
nil
end

def baz(arg1, *args)
end
end
end

Name: SubTest
Reference (reference.call):
SubTest

Name: MyClass
Declaration (definition.class):
class MyClass < SomeClass
include Foo

def self.foo
new.foo
end

class << self
def bar
new.bar(true)
end
end

def foo
self
end

def bar(arg1, arg2 = "fine")
nil
end

def baz(arg1, *args)
end
end
Lineage: [SubTest]
Lineage types: [module]

Name: MyClass
Reference (reference.call):
MyClass

Name: SomeClass
Reference (reference.call):
SomeClass

Name: include
Reference (reference.call):
include Foo

Name: include
Reference (reference.call):
include

Name: Foo
Reference (reference.call):
Foo

Name: foo
Reference (reference.call):
foo

Name: new
Reference (reference.call):
new

Name: foo
Reference (reference.call):
new.foo

Name: foo
Reference (reference.call):
foo

Name: bar
Reference (reference.call):
bar

Name: new
Reference (reference.call):
new

Name: bar
Reference (reference.call):
new.bar(true)

Name: bar
Reference (reference.call):
bar

Name: foo
Reference (reference.call):
foo

Name: bar
Reference (reference.call):
bar

Name: arg1
Reference (reference.call):
arg1

Name: arg2
Reference (reference.call):
arg2

Name: bar
Parameters: (arg1, arg2 = "fine")
Definition (definition.method):
def bar(arg1, arg2 = "fine")
nil
end
Lineage: [SubTest MyClass]
Lineage types: [module class]

Name: baz
Reference (reference.call):
baz

Name: arg1
Reference (reference.call):
arg1

Name: args
Reference (reference.call):
args

Name: Test
Reference (reference.call):
Test

Name: SubTest
Reference (reference.call):
SubTest

Name: SubSubTest
Definition (definition.module):
module Test::SubTest::SubSubTest
module SubSubSubTest
extend Foo
end
end

Name: SubSubTest
Reference (reference.call):
SubSubTest

Name: SubSubSubTest
Definition (definition.module):
module SubSubSubTest
extend Foo
end
Lineage: [SubSubTest]
Lineage types: [module]

Name: SubSubSubTest
Reference (reference.call):
SubSubSubTest

Name: extend
Reference (reference.call):
extend Foo

Name: extend
Reference (reference.call):
extend

Name: Foo
Reference (reference.call):
Foo
11 changes: 8 additions & 3 deletions queries/ruby_tags.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
.
[
(method
name: (_) @name) @definition.method
name: (_) @name
parameters: (method_parameters) @codeium.parameters
body: (_) @body
) @definition.method
(singleton_method
name: (_) @name) @definition.method
name: (_) @name
parameters: (method_parameters) @codeium.parameters
body: (_) @body
) @definition.method
]
(#strip! @doc "^#\\s*")
(#select-adjacent! @doc @definition.method)
Expand Down Expand Up @@ -59,6 +65,5 @@

(
[(identifier) (constant)] @name @reference.call
(#is-not? local)
(#not-match? @name "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
)
46 changes: 46 additions & 0 deletions test_files/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "net/http"

class SomeClass
def nice()
"Nice"
end
end

module Foo
def foo
:foo
end
end

module Test::SubTest
class MyClass < SomeClass
include Foo

def self.foo
new.foo
end

class << self
def bar
new.bar(true)
end
end

def foo
self
end

def bar(arg1, arg2 = "fine")
nil
end

def baz(arg1, *args)
end
end
end

module Test::SubTest::SubSubTest
module SubSubSubTest
extend Foo
end
end

0 comments on commit eee1f30

Please sign in to comment.