Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/ruby_indexer/lib/ruby_indexer/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ def initial_excluded_gems
others.uniq!
others.map!(&:name)

excluded.each do |dependency|
# Collect transitive dependencies in a separate array to avoid modifying `excluded` while iterating over it.
# Modifying an array during `.each` iteration causes Ruby to process newly added elements, which can lead to
# excessive iterations or infinite loops with circular dependencies. See: https://github.com/Shopify/ruby-lsp/issues/3912
transitive_excluded = excluded.each_with_object([]) do |dependency, acc|
next unless dependency.runtime?

spec = dependency.to_spec
Expand All @@ -236,14 +239,15 @@ def initial_excluded_gems
spec.dependencies.each do |transitive_dependency|
next if others.include?(transitive_dependency.name)

excluded << transitive_dependency
acc << transitive_dependency
end
rescue Gem::MissingSpecError
# If a gem is scoped only to some specific platform, then its dependencies may not be installed either, but they
# are still listed in dependencies. We can't index them because they are not installed for the platform, so we
# just ignore if they're missing
end

excluded.concat(transitive_excluded)
excluded.uniq!
excluded.map(&:name)
rescue Bundler::GemfileNotFound
Expand Down