# File lib/ruby_lsp/setup_bundler.rb, line 59defsetup!raiseBundleNotLockedif@gemfile&.exist?&&!@lockfile&.exist?# Do not set up a custom bundle if LSP dependencies are already in the Gemfileif@dependencies["ruby-lsp"] &&@dependencies["debug"] &&
(@dependencies["rails"] ?@dependencies["ruby-lsp-rails"] :true)
$stderr.puts(
"Ruby LSP> Skipping custom bundle setup since LSP dependencies are already in #{@gemfile}",
)
# If the user decided to add `ruby-lsp` and `debug` (and potentially `ruby-lsp-rails`) to their Gemfile after# having already run the Ruby LSP, then we need to remove the `.ruby-lsp` folder, otherwise we will run `bundle# install` for the top level and try to execute the Ruby LSP using the custom bundle, which will fail since the# gems are not installed there@custom_dir.rmtreeif@custom_dir.exist?returnrun_bundle_installend# Automatically create and ignore the .ruby-lsp folder for users@custom_dir.mkpathunless@custom_dir.exist?ignore_file = @custom_dir+".gitignore"ignore_file.write("*") unlessignore_file.exist?write_custom_gemfileunless@gemfile&.exist?&&@lockfile&.exist?$stderr.puts("Ruby LSP> Skipping lockfile copies because there's no top level bundle")
returnrun_bundle_install(@custom_gemfile)
endlockfile_contents = @lockfile.readcurrent_lockfile_hash = Digest::SHA256.hexdigest(lockfile_contents)
if@custom_lockfile.exist?&&@lockfile_hash_path.exist?&&@lockfile_hash_path.read==current_lockfile_hash$stderr.puts(
"Ruby LSP> Skipping custom bundle setup since #{@custom_lockfile} already exists and is up to date",
)
returnrun_bundle_install(@custom_gemfile)
endFileUtils.cp(@lockfile.to_s, @custom_lockfile.to_s)
correct_relative_remote_paths@lockfile_hash_path.write(current_lockfile_hash)
run_bundle_install(@custom_gemfile)
end