Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Aug 27, 2024
1 parent 4c5d60a commit 37ec455
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,26 @@ def existing_or_new_singleton_class(name)
singleton
end

# TODO: fix typing
# 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)]))
# end
def entries_for(path, type = nil)
type = Entry if type.nil?

# TODO: Make this work
# return @files_to_entries[path]&.grep(type)

# old way:
@files_to_entries[path].select do |entry|
# entry.ancestors.include?(RubyIndexer::Entry::Namespace) # FAILS
entry.class == RubyIndexer::Entry::Class || entry.class == RubyIndexer::Entry::Module
end
end

private

# Runs the registered included hooks
Expand Down
16 changes: 16 additions & 0 deletions lib/ruby_indexer/test/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1822,5 +1822,21 @@ class Child < Namespace::Parent
@index.linearized_ancestors_of("Foo::Child::<Class:Child>"),
)
end

def test_entries_for
index(<<~RUBY)
class Foo; end
module Bar
def my_def; end
end
RUBY

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

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

0 comments on commit 37ec455

Please sign in to comment.