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

Ensure we're handling client responses for window show message #2814

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
20 changes: 16 additions & 4 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading