diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index 7716c2ced..316820a8d 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -32,6 +32,7 @@ def initialize(project_path, **options) @project_path = project_path @branch = T.let(options[:branch], T.nilable(String)) @launcher = T.let(options[:launcher], T.nilable(T::Boolean)) + patch_thor_to_print_progress_to_stderr! if @launcher # Regular bundle paths @gemfile = T.let( @@ -400,5 +401,21 @@ def base_bundle_command(env) "bundle" end + + sig { void } + def patch_thor_to_print_progress_to_stderr! + return unless defined?(Bundler::Thor::Shell::Basic) + + Bundler::Thor::Shell::Basic.prepend(Module.new do + extend T::Sig + + sig { returns(IO) } + def stdout + $stderr + end + end) + + Bundler.ui.level = :info + end end end diff --git a/project-words b/project-words index f62fbf35c..5f182c097 100644 --- a/project-words +++ b/project-words @@ -27,6 +27,7 @@ FIXEDENCODING Floo fnmatch fooo +gemname hostedtoolcache importmap indexables diff --git a/sorbet/rbi/shims/bundler.rbi b/sorbet/rbi/shims/bundler.rbi index f48604ba0..87408448f 100644 --- a/sorbet/rbi/shims/bundler.rbi +++ b/sorbet/rbi/shims/bundler.rbi @@ -23,4 +23,10 @@ module Bundler def run; end end end + + module Thor # rubocop:disable Style/ClassAndModuleChildren + module Shell + class Basic; end + end + end end diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index 7bf9492b7..823c58f78 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -714,6 +714,31 @@ def test_invoke_cli_calls_bundler_directly_for_update end end + def test_progress_is_printed_to_stderr + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + File.write(File.join(dir, "Gemfile"), <<~GEMFILE) + source "https://rubygems.org" + gem "rdoc" + GEMFILE + + Bundler.with_unbundled_env do + capture_subprocess_io do + # Run bundle install to generate the lockfile + system("bundle install") + end + + stdout, stderr = capture_subprocess_io do + RubyLsp::SetupBundler.new(dir, launcher: true).setup! + end + + assert_match(/Bundle complete! [\d]+ Gemfile dependencies, [\d]+ gems now installed/, stderr) + assert_empty(stdout) + end + end + end + end + private def with_default_external_encoding(encoding, &block)