Skip to content

Commit 90dc23c

Browse files
authored
Merge pull request #2667 from Shopify/ko/entries-for
Make type optional in Index#entries_for
2 parents 46b0411 + 9f77cf5 commit 90dc23c

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/ruby_indexer/lib/ruby_indexer/index.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,13 @@ def existing_or_new_singleton_class(name)
677677
sig do
678678
type_parameters(:T).params(
679679
path: String,
680-
type: T::Class[T.all(T.type_parameter(:T), Entry)],
681-
).returns(T.nilable(T::Array[T.type_parameter(:T)]))
680+
type: T.nilable(T::Class[T.all(T.type_parameter(:T), Entry)]),
681+
).returns(T.nilable(T.any(T::Array[Entry], T::Array[T.type_parameter(:T)])))
682682
end
683-
def entries_for(path, type)
683+
def entries_for(path, type = nil)
684684
entries = @files_to_entries[path]
685+
return entries unless type
686+
685687
entries&.grep(type)
686688
end
687689

lib/ruby_indexer/test/index_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,9 @@ def self.my_singleton_def; end
18581858

18591859
entries = @index.entries_for("/fake/path/foo.rb", RubyIndexer::Entry::Namespace)
18601860
assert_equal(["Foo", "Bar", "Bar::<Class:Bar>"], entries.map(&:name))
1861+
1862+
entries = @index.entries_for("/fake/path/foo.rb")
1863+
assert_equal(["Foo", "Bar", "my_def", "Bar::<Class:Bar>", "my_singleton_def"], entries.map(&:name))
18611864
end
18621865

18631866
def test_entries_for_returns_nil_if_no_matches

0 commit comments

Comments
 (0)