class RubyIndexer::Configuration
def initial_excluded_gems
def initial_excluded_gems excluded, others = Bundler.definition.dependencies.partition do |dependency| dependency.groups == [:development] end # When working on a gem, we need to make sure that its gemspec dependencies can't be excluded. This is necessary # because Bundler doesn't assign groups to gemspec dependencies # # If the dependency is prerelease, `to_spec` may return `nil` due to a bug in older version of Bundler/RubyGems: # https://github.com/Shopify/ruby-lsp/issues/1246 this_gem = Bundler.definition.dependencies.find do |d| d.to_spec&.full_gem_path == Dir.pwd rescue Gem::MissingSpecError false end others.concat(this_gem.to_spec.dependencies) if this_gem excluded.each do |dependency| next unless dependency.runtime? spec = dependency.to_spec next unless spec spec.dependencies.each do |transitive_dependency| # If the transitive dependency is included in other groups, skip it next if others.any? { |d| d.name == transitive_dependency.name } # If the transitive dependency is included as a transitive dependency of a gem outside of the development # group, skip it next if others.any? { |d| d.to_spec&.dependencies&.include?(transitive_dependency) } excluded << 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.uniq! excluded.map(&:name) end