diff --git a/lib/ruby_lsp/base_server.rb b/lib/ruby_lsp/base_server.rb index b97bea824..f125bf84c 100644 --- a/lib/ruby_lsp/base_server.rb +++ b/lib/ruby_lsp/base_server.rb @@ -8,9 +8,10 @@ class BaseServer abstract! - sig { params(options: T::Boolean).void } + sig { params(options: T.untyped).void } def initialize(**options) @test_mode = T.let(options[:test_mode], T.nilable(T::Boolean)) + @setup_error = T.let(options[:setup_error], T.nilable(StandardError)) @writer = T.let(Transport::Stdio::Writer.new, Transport::Stdio::Writer) @reader = T.let(Transport::Stdio::Reader.new, Transport::Stdio::Reader) @incoming_queue = T.let(Thread::Queue.new, Thread::Queue) @@ -33,6 +34,11 @@ def initialize(**options) @global_state = T.let(GlobalState.new, GlobalState) Thread.main.priority = 1 + + # We read the initialize request in `exe/ruby-lsp` to be able to determine the workspace URI where Bundler should + # be setup + initialize_request = options[:initialize_request] + process_message(initialize_request) if initialize_request end sig { void } diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index d0960f1a1..da38ef472 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -290,6 +290,18 @@ def run_initialize(message) begin_progress("indexing-progress", "Ruby LSP: indexing files") global_state_notifications.each { |notification| send_message(notification) } + + if @setup_error + message = <<~MESSAGE + An error occurred while setting up Bundler. This may be due to a failure when installing dependencies. + The Ruby LSP will continue to run, but features related to the missing dependencies will not be available. + + Error: + #{@setup_error.full_message} + MESSAGE + + send_message(Notification.window_log_message(message, type: Constant::MessageType::ERROR)) + end end sig { void }