Skip to content

Commit 5a24001

Browse files
authored
Merge pull request #890 from Shopify/vs/use_absolute_path_for_running_lsp
Use the absolute BUNDLE_PATH to run the server
2 parents b23dcbe + 75308cc commit 5a24001

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ def run_bundle_install(bundle_gemfile = @gemfile)
156156
# `.ruby-lsp` folder, which is not the user's intention. For example, if the path is configured as `vendor`, we
157157
# want to install it in the top level `vendor` and not `.ruby-lsp/vendor`
158158
path = Bundler.settings["path"]
159+
expanded_path = File.expand_path(path, Dir.pwd) if path
159160

160161
# Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
161162
env = {}
162163
env["BUNDLE_GEMFILE"] = bundle_gemfile.to_s
163-
env["BUNDLE_PATH"] = File.expand_path(path, Dir.pwd) if path
164+
env["BUNDLE_PATH"] = expanded_path if expanded_path
164165

165166
# If both `ruby-lsp` and `debug` are already in the Gemfile, then we shouldn't try to upgrade them or else we'll
166167
# produce undesired source control changes. If the custom bundle was just created and either `ruby-lsp` or `debug`
@@ -187,7 +188,7 @@ def run_bundle_install(bundle_gemfile = @gemfile)
187188
# Add bundle update
188189
warn("Ruby LSP> Running bundle install for the custom bundle. This may take a while...")
189190
system(env, command)
190-
[bundle_gemfile.to_s, path]
191+
[bundle_gemfile.to_s, expanded_path]
191192
end
192193
end
193194
end

test/setup_bundler_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_uses_absolute_bundle_path_for_bundle_install
124124
Bundler.settings.set_global("path", "vendor/bundle")
125125
Object.any_instance.expects(:system).with(bundle_env(".ruby-lsp/Gemfile"), "bundle install 1>&2")
126126
Bundler::LockfileParser.any_instance.expects(:dependencies).returns({}).at_least_once
127-
run_script
127+
run_script(expected_path: File.expand_path("vendor/bundle", Dir.pwd))
128128
ensure
129129
# We need to revert the changes to the bundler config or else this actually changes ~/.bundle/config
130130
Bundler.settings.set_global("path", nil)
@@ -212,8 +212,10 @@ def test_does_nothing_if_both_ruby_lsp_and_debug_are_gemspec_dependencies
212212

213213
# This method runs the script and then immediately unloads it. This allows us to make assertions against the effects
214214
# of running the script multiple times
215-
def run_script(path = "/fake/project/path")
216-
RubyLsp::SetupBundler.new(path).setup!
215+
def run_script(path = "/fake/project/path", expected_path: nil)
216+
_bundle_gemfile, bundle_path = RubyLsp::SetupBundler.new(path).setup!
217+
218+
assert_equal(expected_path, bundle_path) if expected_path
217219
end
218220

219221
def bundle_env(bundle_gemfile = "Gemfile")

0 commit comments

Comments
 (0)