Skip to content

Commit 17a79c2

Browse files
committed
Add rbs to composed bundle update lists
Without rbs in the update list, conservative mode can't resolve ruby-lsp 0.18+ for projects that don't have rbs locked, causing unexpected downgrades to 0.11.2. Fixes #3937
1 parent 936e21f commit 17a79c2

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def bundle_install
331331
def update(env)
332332
# Try to auto upgrade the gems we depend on, unless they are in the Gemfile as that would result in undesired
333333
# source control changes
334-
gems = ["ruby-lsp", "debug", "prism"].reject { |dep| @dependencies[dep] }
334+
gems = ["ruby-lsp", "debug", "prism", "rbs"].reject { |dep| @dependencies[dep] }
335335
gems << "ruby-lsp-rails" if @rails_app && !@dependencies["ruby-lsp-rails"]
336336

337337
Bundler::CLI::Update.new({ conservative: true }, gems).run
@@ -343,14 +343,15 @@ def update(env)
343343

344344
#: (Hash[String, String] env) -> Hash[String, String]
345345
def run_bundle_install_through_command(env)
346-
# If `ruby-lsp` and `debug` (and potentially `ruby-lsp-rails`) are already in the Gemfile, then we shouldn't try
347-
# to upgrade them or else we'll produce undesired source control changes. If the composed bundle was just created
348-
# and any of `ruby-lsp`, `ruby-lsp-rails` or `debug` weren't a part of the Gemfile, then we need to run `bundle
349-
# install` for the first time to generate the Gemfile.lock with them included or else Bundler will complain that
350-
# they're missing. We can only update if the custom `.ruby-lsp/Gemfile.lock` already exists and includes all gems
346+
# If `ruby-lsp`, `debug` and `rbs` (and potentially `ruby-lsp-rails`) are already in the Gemfile, then we
347+
# shouldn't try to upgrade them or else we'll produce undesired source control changes. If the composed bundle was
348+
# just created and any of `ruby-lsp`, `ruby-lsp-rails`, `debug` or `rbs` weren't a part of the Gemfile, then we
349+
# need to run `bundle install` for the first time to generate the Gemfile.lock with them included or else Bundler
350+
# will complain that they're missing. We can only update if the custom `.ruby-lsp/Gemfile.lock` already exists and
351+
# includes all gems
351352

352353
# When not updating, we run `(bundle check || bundle install)`
353-
# When updating, we run `((bundle check && bundle update ruby-lsp debug) || bundle install)`
354+
# When updating, we run `((bundle check && bundle update ruby-lsp debug rbs) || bundle install)`
354355
bundler_path = File.join(Gem.default_bindir, "bundle")
355356
base_command = (!Gem.win_platform? && File.exist?(bundler_path) ? "#{Gem.ruby} #{bundler_path}" : "bundle").dup
356357

@@ -361,12 +362,13 @@ def run_bundle_install_through_command(env)
361362
command = +"(#{base_command} check"
362363

363364
if should_bundle_update?
364-
# If any of `ruby-lsp`, `ruby-lsp-rails` or `debug` are not in the Gemfile, try to update them to the latest
365-
# version
365+
# If any of `ruby-lsp`, `ruby-lsp-rails`, `debug` or `rbs` are not in the Gemfile, try to update them to the
366+
# latest version
366367
command.prepend("(")
367368
command << " && #{base_command} update "
368369
command << "ruby-lsp " unless @dependencies["ruby-lsp"]
369370
command << "debug " unless @dependencies["debug"]
371+
command << "rbs " unless @dependencies["rbs"]
370372
command << "ruby-lsp-rails " if @rails_app && !@dependencies["ruby-lsp-rails"]
371373
command.delete_suffix!(" ")
372374
command << ")"

test/setup_bundler_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_does_not_copy_gemfile_lock_when_not_modified
176176
Bundler.with_unbundled_env do
177177
stub_bundle_with_env(
178178
bundle_env(dir, ".ruby-lsp/Gemfile"),
179-
/((bundle _[\d\.]+_ check && bundle _[\d\.]+_ update ruby-lsp debug) || bundle _[\d\.]+_ install) 1>&2/,
179+
/((bundle _[\d\.]+_ check && bundle _[\d\.]+_ update ruby-lsp debug rbs) || bundle _[\d\.]+_ install) 1>&2/,
180180
)
181181

182182
FileUtils.expects(:cp).never
@@ -732,7 +732,7 @@ def test_invoke_cli_calls_bundler_directly_for_update
732732
require "bundler/cli/update"
733733
Bundler::CLI::Update.expects(:new).with(
734734
{ conservative: true },
735-
["ruby-lsp", "debug", "prism"],
735+
["ruby-lsp", "debug", "prism", "rbs"],
736736
).returns(mock_update)
737737

738738
FileUtils.touch(File.join(dir, ".ruby-lsp", "needs_update"))

0 commit comments

Comments
 (0)