Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make type optional in Index#entries_for #2667

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading