Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions exe/ruby-lsp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ parser = OptionParser.new do |opts|
options[:launcher] = true
end

opts.on("--beta", "Use pre-release server gems") do
options[:beta] = true
end

opts.on("-h", "--help", "Print this help") do
puts opts.help
puts
Expand Down Expand Up @@ -66,6 +70,7 @@ if ENV["BUNDLE_GEMFILE"].nil?
if options[:launcher]
flags = []
flags << "--debug" if options[:debug]
flags << "--beta" if options[:beta]
exit exec(Gem.ruby, File.expand_path("ruby-lsp-launcher", __dir__), *flags)
end

Expand Down
8 changes: 5 additions & 3 deletions exe/ruby-lsp-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ pid = if Gem.win_platform?
["-I", File.expand_path(path)]
end

Process.spawn(
args = [
Gem.ruby,
*load_path,
File.expand_path("../lib/ruby_lsp/scripts/compose_bundle_windows.rb", __dir__),
raw_initialize,
)
]
args << "--beta" if ARGV.include?("--beta")
Process.spawn(*args)
else
fork do
require_relative "../lib/ruby_lsp/scripts/compose_bundle"
compose(raw_initialize)
compose(raw_initialize, beta: ARGV.include?("--beta"))
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lsp/scripts/compose_bundle.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# typed: true
# frozen_string_literal: true

def compose(raw_initialize)
def compose(raw_initialize, beta: false)
require_relative "../setup_bundler"
require "json"
require "uri"
Expand All @@ -12,7 +12,7 @@ def compose(raw_initialize)
workspace_path = workspace_uri && URI(workspace_uri).to_standardized_path
workspace_path ||= Dir.pwd

env = RubyLsp::SetupBundler.new(workspace_path, launcher: true).setup!
env = RubyLsp::SetupBundler.new(workspace_path, launcher: true, beta: beta).setup!

File.open(File.join(".ruby-lsp", "bundle_env"), "w") do |f|
f.flock(File::LOCK_EX)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/scripts/compose_bundle_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

# When this is invoked on Windows, we pass the raw initialize as an argument to this script. On other platforms, we
# invoke the compose method from inside a forked process
compose(ARGV.first)
compose(ARGV.first, beta: ARGV.include?("--beta"))
2 changes: 2 additions & 0 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def initialize(project_path, **options)
@project_path = project_path
@branch = options[:branch] #: String?
@launcher = options[:launcher] #: bool?
@beta = options[:beta] #: bool?
force_output_to_stderr! if @launcher

# Regular bundle paths
Expand Down Expand Up @@ -170,6 +171,7 @@ def write_custom_gemfile

unless @dependencies["ruby-lsp"]
ruby_lsp_entry = +'gem "ruby-lsp", require: false, group: :development'
ruby_lsp_entry << ", \">= 0.a\"" if @beta
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\"" if @branch
parts << ruby_lsp_entry
end
Expand Down
76 changes: 76 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,82 @@ def test_is_resilient_to_pipe_being_closed_by_client_during_compose
end
end

def test_beta_adds_prerelease_constraint_to_composed_gemfile
in_temp_dir do |dir|
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "rdoc"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle install")
run_script(dir, beta: true)
end
end

gemfile_content = File.read(File.join(dir, ".ruby-lsp", "Gemfile"))
assert_match(/gem "ruby-lsp", require: false, group: :development, ">= 0.a"/, gemfile_content)
end
end

def test_beta_adds_prerelease_constraint_to_composed_gemfile_in_launcher_mode
in_temp_dir do |dir|
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "rdoc"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle install")
RubyLsp::SetupBundler.new(dir, launcher: true, beta: true).setup!
end
end

gemfile_content = File.read(File.join(dir, ".ruby-lsp", "Gemfile"))
assert_match(/gem "ruby-lsp", require: false, group: :development, ">= 0.a"/, gemfile_content)
end
end

def test_beta_has_no_effect_when_ruby_lsp_is_in_the_bundle_in_launcher_mode
in_temp_dir do |dir|
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "ruby-lsp"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle install")
RubyLsp::SetupBundler.new(dir, launcher: true, beta: true).setup!
end
end

gemfile_content = File.read(File.join(dir, ".ruby-lsp", "Gemfile"))
refute_match(/gem "ruby-lsp", require: false, group: :development, ">= 0.a"/, gemfile_content)
end
end

def test_beta_has_no_effect_when_ruby_lsp_is_in_the_bundle
in_temp_dir do |dir|
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "ruby-lsp"
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env do
system("bundle install")
run_script(dir, beta: true)
end
end

gemfile_content = File.read(File.join(dir, ".ruby-lsp", "Gemfile"))
refute_match(/gem "ruby-lsp", require: false, group: :development, ">= 0.a"/, gemfile_content)
end
end

private

def in_temp_dir(&block)
Expand Down
Loading