Skip to content

Commit

Permalink
Print Bundler progress to stderr when invoking CLI directly
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Oct 29, 2024
1 parent bbc0a44 commit 52744c1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@
# the Ruby LSP without including the gem in their application's Gemfile while at the same time giving us access to the
# exact locked versions of dependencies.

Bundler.ui.level = :silent
# Language servers can't print to stdout or that breaks the connection with the editor, but we still want to be able to
# display progress coming from Bundler. Here we patch the basic Thor shell to always print to stderr, so that progress
# appears in the editor without breaking the communication
module Bundler
class Thor
module Shell
class Basic
module Patch
def stdout
$stderr
end
end

prepend(Patch)
end
end
end
end

Bundler.ui.level = :info

module RubyLsp
class SetupBundler
Expand Down
26 changes: 26 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,32 @@ 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_match(/Use `bundle info \[gemname\]` to see where a bundled gem is installed/, stderr)
assert_empty(stdout)
end
end
end
end

private

def with_default_external_encoding(encoding, &block)
Expand Down

0 comments on commit 52744c1

Please sign in to comment.