From 3122d59302b7820704ca5f7622bea2900bcf7d63 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 12 Dec 2024 13:34:01 -0500 Subject: [PATCH] Fix debug platform inclusion for Windows --- lib/ruby_lsp/setup_bundler.rb | 8 +++++++- test/setup_bundler_test.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index 45c4b59ce..1fc7ce891 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -152,7 +152,13 @@ def write_custom_gemfile end unless @dependencies["debug"] - parts << 'gem "debug", require: false, group: :development, platforms: :mri' + # The `mri` platform excludes Windows. We want to install the debug gem only on MRI for any operating system, + # but that constraint doesn't yet exist in Bundler. On Windows, we are manually checking if the engine is MRI + parts << if Gem.win_platform? + 'gem "debug", require: false, group: :development, install_if: -> { RUBY_ENGINE == "ruby" }' + else + 'gem "debug", require: false, group: :development, platforms: :mri' + end end if @rails_app && !@dependencies["ruby-lsp-rails"] diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index b7cb8980f..6b02b8299 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -823,6 +823,39 @@ def test_is_resilient_to_gemfile_changes_in_the_middle_of_setup end end + def test_composed_bundle_includes_debug + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + File.write(File.join(dir, "Gemfile"), <<~GEMFILE) + source "https://rubygems.org" + GEMFILE + + env = T.let({}, T::Hash[String, T.untyped]) + + Bundler.with_unbundled_env do + env = ENV.to_hash + + capture_subprocess_io do + system("bundle install") + assert_path_exists("Gemfile.lock") + + new_env = RubyLsp::SetupBundler.new(dir, launcher: true).setup! + env["BUNDLE_GEMFILE"] = new_env["BUNDLE_GEMFILE"] + env["BUNDLE_PATH"] = new_env["BUNDLE_PATH"] if new_env["BUNDLE_PATH"] + end + end + + Bundler.with_unbundled_env do + _stdout, stderr = capture_subprocess_io do + system(env, "bundle exec ruby -e 'require \"debug\"'") + end + + assert_empty(stderr) + end + end + end + end + private def with_default_external_encoding(encoding, &block)