diff --git a/lib/ruby_indexer/lib/ruby_indexer/configuration.rb b/lib/ruby_indexer/lib/ruby_indexer/configuration.rb index f189121f6..2c9a65871 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/configuration.rb @@ -273,6 +273,9 @@ def initial_excluded_gems end others.concat(this_gem.to_spec.dependencies) if this_gem + others.concat(others.filter_map { |d| d.to_spec&.dependencies }.flatten) + others.uniq! + others.map!(&:name) excluded.each do |dependency| next unless dependency.runtime? @@ -281,12 +284,7 @@ def initial_excluded_gems 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) } + next if others.include?(transitive_dependency.name) excluded << transitive_dependency end diff --git a/lib/ruby_indexer/test/configuration_test.rb b/lib/ruby_indexer/test/configuration_test.rb index f74960118..f807208d3 100644 --- a/lib/ruby_indexer/test/configuration_test.rb +++ b/lib/ruby_indexer/test/configuration_test.rb @@ -166,5 +166,37 @@ def test_includes_top_level_files assert(uris.find { |u| File.basename(u.full_path) == "find_me.rb" }) end end + + def test_transitive_dependencies_for_non_dev_gems_are_not_excluded + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + # Both IRB and debug depend on reline. Since IRB is in the default group, reline should not be excluded + File.write(File.join(dir, "Gemfile"), <<~RUBY) + source "https://rubygems.org" + gem "irb" + gem "ruby-lsp", path: "#{Bundler.root}" + + group :development do + gem "debug" + end + RUBY + + Bundler.with_unbundled_env do + system("bundle install") + + stdout, _stderr = capture_subprocess_io do + script = "puts RubyIndexer::Configuration.new.send(:initial_excluded_gems).join(\",\")" + + system("bundle exec ruby -rruby_lsp/internal -e '#{script}'") + end + + excluded_gems = stdout.split(",") + assert_includes(excluded_gems, "debug") + refute_includes(excluded_gems, "reline") + refute_includes(excluded_gems, "irb") + end + end + end + end end end