From 92f411f01efa5a0820814d3066f74d021b5d22cc Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 25 Feb 2022 15:20:42 -0700 Subject: [PATCH] Extract generic forward_project_request function on server All these methods did the same thing with different message types. Co-Authored-By: Max Brunsfeld --- crates/server/src/rpc.rs | 225 +++++---------------------------------- 1 file changed, 24 insertions(+), 201 deletions(-) diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index c7762bd759..7887cb763e 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -12,7 +12,7 @@ use collections::{HashMap, HashSet}; use futures::{channel::mpsc, future::BoxFuture, FutureExt, SinkExt, StreamExt}; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use rpc::{ - proto::{self, AnyTypedEnvelope, EnvelopedMessage, RequestMessage}, + proto::{self, AnyTypedEnvelope, EntityMessage, EnvelopedMessage, RequestMessage}, Connection, ConnectionId, Peer, TypedEnvelope, }; use sha1::{Digest as _, Sha1}; @@ -77,26 +77,28 @@ impl Server { .add_message_handler(Server::update_diagnostic_summary) .add_message_handler(Server::disk_based_diagnostics_updating) .add_message_handler(Server::disk_based_diagnostics_updated) - .add_request_handler(Server::get_definition) - .add_request_handler(Server::get_references) - .add_request_handler(Server::search_project) - .add_request_handler(Server::get_document_highlights) - .add_request_handler(Server::get_project_symbols) - .add_request_handler(Server::open_buffer_for_symbol) - .add_request_handler(Server::open_buffer) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler( + Server::forward_project_request::, + ) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) + .add_request_handler(Server::forward_project_request::) .add_message_handler(Server::close_buffer) .add_request_handler(Server::update_buffer) .add_message_handler(Server::update_buffer_file) .add_message_handler(Server::buffer_reloaded) .add_message_handler(Server::buffer_saved) .add_request_handler(Server::save_buffer) - .add_request_handler(Server::format_buffers) - .add_request_handler(Server::get_completions) - .add_request_handler(Server::apply_additional_edits_for_completion) - .add_request_handler(Server::get_code_actions) - .add_request_handler(Server::apply_code_action) - .add_request_handler(Server::prepare_rename) - .add_request_handler(Server::perform_rename) .add_request_handler(Server::get_channels) .add_request_handler(Server::get_users) .add_request_handler(Server::join_channel) @@ -543,97 +545,16 @@ impl Server { Ok(()) } - async fn get_definition( + async fn forward_project_request( self: Arc, - request: TypedEnvelope, - ) -> tide::Result { + request: TypedEnvelope, + ) -> tide::Result + where + T: EntityMessage + RequestMessage, + { let host_connection_id = self .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host_connection_id, request.payload) - .await?) - } - - async fn get_references( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host_connection_id = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host_connection_id, request.payload) - .await?) - } - - async fn search_project( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host_connection_id = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host_connection_id, request.payload) - .await?) - } - - async fn get_document_highlights( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host_connection_id = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host_connection_id, request.payload) - .await?) - } - - async fn get_project_symbols( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host_connection_id = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host_connection_id, request.payload) - .await?) - } - - async fn open_buffer_for_symbol( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host_connection_id = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host_connection_id, request.payload) - .await?) - } - - async fn open_buffer( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host_connection_id = self - .state() - .read_project(request.payload.project_id, request.sender_id)? + .read_project(request.payload.remote_entity_id(), request.sender_id)? .host_connection_id; Ok(self .peer @@ -680,104 +601,6 @@ impl Server { Ok(response) } - async fn format_buffers( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - - async fn get_completions( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - - async fn apply_additional_edits_for_completion( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - - async fn get_code_actions( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - - async fn apply_code_action( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - - async fn prepare_rename( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - - async fn perform_rename( - self: Arc, - request: TypedEnvelope, - ) -> tide::Result { - let host = self - .state() - .read_project(request.payload.project_id, request.sender_id)? - .host_connection_id; - Ok(self - .peer - .forward_request(request.sender_id, host, request.payload.clone()) - .await?) - } - async fn update_buffer( self: Arc, request: TypedEnvelope,