diff --git a/lib/ruby_indexer/lib/ruby_indexer/index.rb b/lib/ruby_indexer/lib/ruby_indexer/index.rb index 9e63ffedc..dc2353408 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/index.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/index.rb @@ -619,13 +619,12 @@ def existing_or_new_singleton_class(name) sig do type_parameters(:T).params( path: String, - type: T.nilable(T::Class[T.all(T.type_parameter(:T), Entry)]), - ).returns(T::Array[T.type_parameter(:T)]) + type: T::Class[T.all(T.type_parameter(:T), Entry)], + ).returns(T.nilable(T::Array[T.type_parameter(:T)])) end - def entries_for(path, type = nil) - type = Entry if type.nil? - - Array(@files_to_entries[path]).grep(type) + def entries_for(path, type) + entries = @files_to_entries[path] + entries&.grep(type) end private diff --git a/lib/ruby_indexer/test/index_test.rb b/lib/ruby_indexer/test/index_test.rb index b34989608..7e1f5a111 100644 --- a/lib/ruby_indexer/test/index_test.rb +++ b/lib/ruby_indexer/test/index_test.rb @@ -1853,7 +1853,7 @@ def self.my_singleton_def; end end RUBY - entries = @index.entries_for("/fake/path/foo.rb") + entries = @index.entries_for("/fake/path/foo.rb", Entry) assert_equal(["Foo", "Bar", "my_def", "Bar::", "my_singleton_def"], entries.map(&:name)) entries = @index.entries_for("/fake/path/foo.rb", RubyIndexer::Entry::Namespace) @@ -1861,7 +1861,7 @@ def self.my_singleton_def; end end def test_entries_for_returns_nil_if_no_matches - assert_empty(@index.entries_for("non_existing_file.rb")) + assert_nil(@index.entries_for("non_existing_file.rb", Entry::Namespace)) end end end