From 8d1f7b7e31cbe9702878fb0f1192f314d1d13932 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 31 Oct 2024 16:14:33 -0400 Subject: [PATCH] Ensure we're handling client responses for window show message --- lib/ruby_lsp/server.rb | 20 ++++++++++++++++---- test/server_test.rb | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index 0de646c81..340f99a7d 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -81,8 +81,6 @@ def process_message(message) workspace_did_change_watched_files(message) when "workspace/symbol" workspace_symbol(message) - when "window/showMessageRequest" - window_show_message_request(message) when "rubyLsp/textDocument/showSyntaxTree" text_document_show_syntax_tree(message) when "rubyLsp/workspace/dependencies" @@ -108,6 +106,8 @@ def process_message(message) ) when "$/cancelRequest" @mutex.synchronize { @cancelled_requests << message[:params][:id] } + when nil + process_response(message) if message[:result] end rescue DelegateRequestError send_message(Error.new(id: message[:id], code: DelegateRequestError::CODE, message: "DELEGATE_REQUEST")) @@ -140,6 +140,15 @@ def process_message(message) send_log_message("Error processing #{message[:method]}: #{e.full_message}", type: Constant::MessageType::ERROR) end + # Process responses to requests that were sent to the client + sig { params(message: T::Hash[Symbol, T.untyped]).void } + def process_response(message) + case message.dig(:result, :method) + when "window/showMessageRequest" + window_show_message_request(message) + end + end + sig { params(include_project_addons: T::Boolean).void } def load_addons(include_project_addons: true) # If invoking Bundler.setup failed, then the load path will not be configured properly and trying to load add-ons @@ -1226,11 +1235,14 @@ def process_indexing_configuration(indexing_options) sig { params(message: T::Hash[Symbol, T.untyped]).void } def window_show_message_request(message) - addon_name = message[:addon_name] + result = message[:result] + return unless result + + addon_name = result[:addon_name] addon = Addon.addons.find { |addon| addon.name == addon_name } return unless addon - addon.handle_window_show_message_response(message[:title]) + addon.handle_window_show_message_response(result[:title]) end end end diff --git a/test/server_test.rb b/test/server_test.rb index d0ae7faed..8f8e9e993 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -696,7 +696,7 @@ def handle_window_show_message_response(title) addon = RubyLsp::Addon.addons.find { |a| a.is_a?(klass) } addon.expects(:handle_window_show_message_response).with("hello") - @server.process_message(method: "window/showMessageRequest", title: "hello", addon_name: "My Add-on") + @server.process_message(result: { method: "window/showMessageRequest", title: "hello", addon_name: "My Add-on" }) ensure RubyLsp::Addon.addons.clear RubyLsp::Addon.addon_classes.clear