Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start returning composed bundle environment from initialize request #2880

Merged
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
3 changes: 0 additions & 3 deletions exe/ruby-lsp-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ rescue StandardError => e
# If Bundler.setup fails, we need to restore the original $LOAD_PATH so that we can still require the Ruby LSP server
# in degraded mode
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
ensure
require "fileutils"
FileUtils.rm(bundle_env_path) if File.exist?(bundle_env_path)
end

error_path = File.join(".ruby-lsp", "install_error")
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "prism/visitor"
require "language_server-protocol"
require "rbs"
require "fileutils"

require "ruby-lsp"
require "ruby_lsp/base_server"
Expand Down
8 changes: 8 additions & 0 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def run_initialize(message)
Hash.new(true)
end

bundle_env_path = File.join(".ruby-lsp", "bundle_env")
bundle_env = if File.exist?(bundle_env_path)
env = File.readlines(bundle_env_path).to_h { |line| T.cast(line.chomp.split("=", 2), [String, String]) }
graphite-app[bot] marked this conversation as resolved.
Show resolved Hide resolved
FileUtils.rm(bundle_env_path)
env
end

document_symbol_provider = Requests::DocumentSymbol.provider if enabled_features["documentSymbols"]
document_link_provider = Requests::DocumentLink.provider if enabled_features["documentLink"]
code_lens_provider = Requests::CodeLens.provider if enabled_features["codeLens"]
Expand Down Expand Up @@ -269,6 +276,7 @@ def run_initialize(message)
},
formatter: @global_state.formatter,
degraded_mode: !!(@install_error || @setup_error),
bundle_env: bundle_env,
}

send_message(Result.new(id: message[:id], response: response))
Expand Down
1 change: 1 addition & 0 deletions project-words
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ quxx
quux
qorge
rdbg
readlines
realpath
reparsing
requireds
Expand Down
23 changes: 23 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ def test_initialize_enabled_features_with_array
assert_includes(capabilities, "semanticTokensProvider")
end

def test_initialize_returns_bundle_env
bundle_env_path = File.join(".ruby-lsp", "bundle_env")
FileUtils.mkdir(".ruby-lsp") unless File.exist?(".ruby-lsp")
File.write(bundle_env_path, "BUNDLE_PATH=vendor/bundle")
@server.process_message({
id: 1,
method: "initialize",
params: {
initializationOptions: { enabledFeatures: [] },
capabilities: { general: { positionEncodings: ["utf-8"] } },
},
})

result = find_message(RubyLsp::Result, id: 1)
hash = JSON.parse(result.response.to_json)

begin
assert_equal({ "BUNDLE_PATH" => "vendor/bundle" }, hash["bundle_env"])
ensure
FileUtils.rm(bundle_env_path) if File.exist?(bundle_env_path)
end
end

def test_initialize_enabled_features_with_hash
capture_subprocess_io do
@server.process_message({
Expand Down
Loading