lib/ruby_indexer/lib/ruby_indexer/index.rb in ruby-lsp-0.11.1 vs lib/ruby_indexer/lib/ruby_indexer/index.rb in ruby-lsp-0.11.2
- old
+ new
@@ -128,11 +128,11 @@
sig { params(name: String, nesting: T::Array[String]).returns(T.nilable(T::Array[Entry])) }
def resolve(name, nesting)
if name.start_with?("::")
name = name.delete_prefix("::")
results = @entries[name] || @entries[follow_aliased_namespace(name)]
- return results.map { |e| e.is_a?(Entry::UnresolvedAlias) ? resolve_alias(e) : e } if results
+ return results&.map { |e| e.is_a?(Entry::UnresolvedAlias) ? resolve_alias(e) : e }
end
nesting.length.downto(0).each do |i|
namespace = T.must(nesting[0...i]).join("::")
full_name = namespace.empty? ? name : "#{namespace}::#{name}"
@@ -159,12 +159,13 @@
end
sig { params(indexable_path: IndexablePath, source: T.nilable(String)).void }
def index_single(indexable_path, source = nil)
content = source || File.read(indexable_path.full_path)
- visitor = IndexVisitor.new(self, YARP.parse(content), indexable_path.full_path)
- visitor.run
+ result = YARP.parse(content)
+ visitor = IndexVisitor.new(self, result, indexable_path.full_path)
+ result.value.accept(visitor)
require_path = indexable_path.require_path
@require_paths_tree.insert(require_path, indexable_path) if require_path
rescue Errno::EISDIR
# If `path` is a directory, just ignore it and continue indexing
@@ -180,9 +181,11 @@
# If we find an alias, then we want to follow its target. In the same example, if `Foo::Bar` is an alias to
# `Something::Else`, then we first discover `Something::Else::Baz`. But `Something::Else::Baz` might contain other
# aliases, so we have to invoke `follow_aliased_namespace` again to check until we only return a real name
sig { params(name: String).returns(String) }
def follow_aliased_namespace(name)
+ return name if @entries[name]
+
parts = name.split("::")
real_parts = []
(parts.length - 1).downto(0).each do |i|
current_name = T.must(parts[0..i]).join("::")