lib/ruby_indexer/lib/ruby_indexer/index.rb in ruby-lsp-0.21.3 vs lib/ruby_indexer/lib/ruby_indexer/index.rb in ruby-lsp-0.22.0

- old
+ new

@@ -5,10 +5,11 @@ class Index extend T::Sig class UnresolvableAliasError < StandardError; end class NonExistingNamespaceError < StandardError; end + class IndexNotEmptyError < StandardError; end # The minimum Jaro-Winkler similarity score for an entry to be considered a match for a given fuzzy search query ENTRY_SIMILARITY_THRESHOLD = 0.7 sig { returns(Configuration) } @@ -37,28 +38,19 @@ @require_paths_tree = T.let(PrefixTree[IndexablePath].new, PrefixTree[IndexablePath]) # Holds the linearized ancestors list for every namespace @ancestors = T.let({}, T::Hash[String, T::Array[String]]) - # List of classes that are enhancing the index - @enhancements = T.let([], T::Array[Enhancement]) - # Map of module name to included hooks that have to be executed when we include the given module @included_hooks = T.let( {}, T::Hash[String, T::Array[T.proc.params(index: Index, base: Entry::Namespace).void]], ) @configuration = T.let(RubyIndexer::Configuration.new, Configuration) end - # Register an enhancement to the index. Enhancements must conform to the `Enhancement` interface - sig { params(enhancement: Enhancement).void } - def register_enhancement(enhancement) - @enhancements << enhancement - end - # Register an included `hook` that will be executed when `module_name` is included into any namespace sig { params(module_name: String, hook: T.proc.params(index: Index, base: Entry::Namespace).void).void } def register_included_hook(module_name, &hook) (@included_hooks[module_name] ||= []) << hook end @@ -358,10 +350,19 @@ indexable_paths: T::Array[IndexablePath], block: T.nilable(T.proc.params(progress: Integer).returns(T::Boolean)), ).void end def index_all(indexable_paths: @configuration.indexables, &block) + # When troubleshooting an indexing issue, e.g. through irb, it's not obvious that `index_all` will augment the + # existing index values, meaning it may contain 'stale' entries. This check ensures that the user is aware of this + # behavior and can take appropriate action. + # binding.break + if @entries.any? + raise IndexNotEmptyError, + "The index is not empty. To prevent invalid entries, `index_all` can only be called once." + end + RBSIndexer.new(self).index_ruby_core # Calculate how many paths are worth 1% of progress progress_step = (indexable_paths.length / 100.0).ceil indexable_paths.each_with_index do |path, index| @@ -384,10 +385,9 @@ self, dispatcher, result, indexable_path.full_path, collect_comments: collect_comments, - enhancements: @enhancements, ) dispatcher.dispatch(result.value) indexing_errors = listener.indexing_errors.uniq