Skip to content

Commit

Permalink
Fix debug platform inclusion for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Dec 12, 2024
1 parent d244ad2 commit d729aaf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
32 changes: 32 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,38 @@ 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(nil, T.nilable(T::Hash[String, String]))

Bundler.with_unbundled_env do
capture_subprocess_io do
# Run bundle install to generate the lockfile
system("bundle install")
env = RubyLsp::SetupBundler.new(dir, launcher: true).setup!
end
end

gemfile_path = File.join(dir, ".ruby-lsp", "Gemfile")
assert_match("debug", File.read(gemfile_path))
assert_match("ruby-lsp", File.read(gemfile_path))

_stdout, stderr = capture_subprocess_io do
Bundler.with_unbundled_env do
system(T.must(env), "bundle exec ruby -e 'require \"debug\"'")
end
end

assert_empty(stderr)
end
end
end

private

def with_default_external_encoding(encoding, &block)
Expand Down

0 comments on commit d729aaf

Please sign in to comment.