Skip to content

Commit

Permalink
Migrate Index to use Indexables
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Aug 29, 2023
1 parent e62652f commit 2469629
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/ruby_indexer/lib/ruby_indexer/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2469629

Please sign in to comment.