Skip to content

Commit

Permalink
Return empty array instead of nil if no matches
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Aug 28, 2024
1 parent 67727d2 commit 3d2ca2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,13 +617,13 @@ 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.nilable(T::Array[T.type_parameter(:T)]))
type: T::Class[T.all(T.type_parameter(:T), Entry)],
).returns(T::Array[T.type_parameter(:T)])
end
def entries_for(path, type = nil)
type = Entry if type.nil?

@files_to_entries[path]&.grep(type)&.grep_v(RubyIndexer::Entry::SingletonClass)
Array(@files_to_entries[path]).grep(type).grep_v(RubyIndexer::Entry::SingletonClass)
end

private
Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1839,5 +1839,9 @@ def self.my_singleton_def; end
entries = @index.entries_for("/fake/path/foo.rb", RubyIndexer::Entry::Namespace)
assert_equal(["Foo", "Bar"], entries.map(&:name))
end

def test_entries_for_returns__nil_if_no_matches
assert_empty(@index.entries_for("non_existing_file.rb"))
end
end
end

0 comments on commit 3d2ca2e

Please sign in to comment.