Skip to content

Commit

Permalink
Make type optional in Index#entries_for
Browse files Browse the repository at this point in the history
  • Loading branch information
KaanOzkan committed Oct 4, 2024
1 parent 0a710db commit 9f77cf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,13 @@ def existing_or_new_singleton_class(name)
sig do
type_parameters(:T).params(
path: String,
type: T::Class[T.all(T.type_parameter(:T), Entry)],
).returns(T.nilable(T::Array[T.type_parameter(:T)]))
type: T.nilable(T::Class[T.all(T.type_parameter(:T), Entry)]),
).returns(T.nilable(T.any(T::Array[Entry], T::Array[T.type_parameter(:T)])))
end
def entries_for(path, type)
def entries_for(path, type = nil)
entries = @files_to_entries[path]
return entries unless type

entries&.grep(type)
end

Expand Down
3 changes: 3 additions & 0 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,9 @@ def self.my_singleton_def; end

entries = @index.entries_for("/fake/path/foo.rb", RubyIndexer::Entry::Namespace)
assert_equal(["Foo", "Bar", "Bar::<Class:Bar>"], entries.map(&:name))

entries = @index.entries_for("/fake/path/foo.rb")
assert_equal(["Foo", "Bar", "my_def", "Bar::<Class:Bar>", "my_singleton_def"], entries.map(&:name))
end

def test_entries_for_returns_nil_if_no_matches
Expand Down

0 comments on commit 9f77cf5

Please sign in to comment.