From 2469629324d08ee20b74e2f340253e25b515d874 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 29 Aug 2023 16:51:21 -0400 Subject: [PATCH] Migrate Index to use Indexables --- lib/ruby_indexer/lib/ruby_indexer/index.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/ruby_indexer/lib/ruby_indexer/index.rb b/lib/ruby_indexer/lib/ruby_indexer/index.rb index a61fecff3b..ea6a4d1b13 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/index.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/index.rb @@ -25,11 +25,11 @@ def initialize @files_to_entries = T.let({}, T::Hash[String, T::Array[Entry]]) end - sig { params(path: String).void } - def delete(path) + sig { params(indexable: Indexable).void } + def delete(indexable) # For each constant discovered in `path`, delete the associated entry from the index. If there are no entries # left, delete the constant from the index. - @files_to_entries[path]&.each do |entry| + @files_to_entries[indexable.full_path]&.each do |entry| entries = @entries[entry.name] next unless entries @@ -39,7 +39,7 @@ def delete(path) @entries.delete(entry.name) if entries.empty? end - @files_to_entries.delete(path) + @files_to_entries.delete(indexable.full_path) end sig { params(entry: Entry).void } @@ -85,15 +85,15 @@ def resolve(name, nesting) nil end - sig { params(paths: T::Array[String]).void } - def index_all(paths: RubyIndexer.configuration.files_to_index) - paths.each { |path| index_single(path) } + sig { params(indexables: T::Array[Indexable]).void } + def index_all(indexables: RubyIndexer.configuration.indexables) + indexables.each { |indexable| index_single(indexable) } end - sig { params(path: String, source: T.nilable(String)).void } - def index_single(path, source = nil) - content = source || File.read(path) - visitor = IndexVisitor.new(self, YARP.parse(content), path) + sig { params(indexable: Indexable, source: T.nilable(String)).void } + def index_single(indexable, source = nil) + content = source || File.read(indexable.full_path) + visitor = IndexVisitor.new(self, YARP.parse(content), indexable.full_path) visitor.run rescue Errno::EISDIR # If `path` is a directory, just ignore it and continue indexing