Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Oct 18, 2023
1 parent 5fa5394 commit 0be4fa1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
7 changes: 6 additions & 1 deletion lib/ruby_indexer/lib/ruby_indexer/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,23 @@ class Method < Entry
sig { returns(T::Array[Parameter]) }
attr_reader :parameters

sig { returns(String) }
attr_reader :namespace

sig do
params(
name: String,
file_path: String,
location: Prism::Location,
comments: T::Array[String],
parameters_node: T.nilable(Prism::ParametersNode),
namespace: T.nilable(String) # nilable or not?
).void
end
def initialize(name, file_path, location, comments, parameters_node)
def initialize(name, file_path, location, comments, parameters_node, namespace = nil)
super(name, file_path, location, comments)
@parameters = T.let(list_params(parameters_node), T::Array[Parameter])
@namespace = T.let(namespace, T.nilable(String))
end

private
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby_indexer/lib/ruby_indexer/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def visit_def_node(node)
else
return
end
@index << entry_class.new(method_name, @file_path, node.location, comments, node.parameters)
name = @stack.join("::")

@index << entry_class.new(method_name, @file_path, node.location, comments, node.parameters, name)
end

private
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby_indexer/test/method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def bar
end
RUBY

assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5")
assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5", "Foo")
end

def test_singleton_method_using_class_self
Expand All @@ -29,8 +29,8 @@ def baz
end
RUBY

assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:2-4:3-7")
assert_entry("baz", Entry::InstanceMethod, "/fake/path/foo.rb:6-2:7-5")
assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:2-4:3-7", "Foo")
assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:2-4:3-7", "Foo")
end

def test_singleton_method_using_class_self_with_nesting
Expand All @@ -45,7 +45,7 @@ def bar
end
RUBY

assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:3-6:4-9")
assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:3-6:4-9", "Foo::Nested")
end

def test_singleton_method_using_class
Expand All @@ -56,7 +56,7 @@ def self.bar
end
RUBY

assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:1-2:2-5")
assert_entry("bar", Entry::SingletonMethod, "/fake/path/foo.rb:1-2:2-5", "Foo")
end

def test_singleton_method_using_other_receiver_is_not_indexed
Expand Down Expand Up @@ -94,7 +94,7 @@ def bar((a, (b, )))
end
RUBY

assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5")
assert_entry("bar", Entry::InstanceMethod, "/fake/path/foo.rb:1-2:2-5", "Foo")
entry = T.must(@index["bar"].first)
assert_equal(1, entry.parameters.length)
parameter = entry.parameters.first
Expand Down
3 changes: 2 additions & 1 deletion lib/ruby_indexer/test/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index(source)
@index.index_single(IndexablePath.new(nil, "/fake/path/foo.rb"), source)
end

def assert_entry(expected_name, type, expected_location)
def assert_entry(expected_name, type, expected_location, expected_namespace = nil)
entries = @index[expected_name]
refute_empty(entries, "Expected #{expected_name} to be indexed")

Expand All @@ -28,6 +28,7 @@ def assert_entry(expected_name, type, expected_location)
":#{location.end_line - 1}-#{location.end_column}"

assert_equal(expected_location, location_string)
assert_equal(expected_namespace, entry.namespace) if expected_namespace
end

def refute_entry(expected_name)
Expand Down

0 comments on commit 0be4fa1

Please sign in to comment.