From d70524421051f579a7e7d596a77a1f9889a096bb Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 18 Feb 2022 18:12:10 +0100 Subject: [PATCH] WIP --- crates/client/src/client.rs | 27 +++++++++++++++-------- crates/editor/src/editor.rs | 44 ++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 157ecf3af6..93ab2c6ad6 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -817,19 +817,28 @@ impl Client { self.peer.send(self.connection_id()?, message) } - pub async fn request(&self, request: T) -> Result { + pub fn request( + &self, + request: T, + ) -> impl Future> { + let client_id = self.id; log::debug!( "rpc request start. client_id: {}. name:{}", - self.id, + client_id, T::NAME ); - let response = self.peer.request(self.connection_id()?, request).await; - log::debug!( - "rpc request finish. client_id: {}. name:{}", - self.id, - T::NAME - ); - response + let response = self + .connection_id() + .map(|conn_id| self.peer.request(conn_id, request)); + async move { + let response = response?.await; + log::debug!( + "rpc request finish. client_id: {}. name:{}", + client_id, + T::NAME + ); + response + } } fn respond(&self, receipt: Receipt, response: T::Response) -> Result<()> { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index ae3c10495f..465cbac3ca 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4146,21 +4146,49 @@ impl Editor { ) -> Option>> { let editor = workspace.active_item(cx)?.act_as::(cx)?; - let (buffer, position, new_name) = editor.update(cx, |editor, cx| { + let (buffer, range, new_name) = editor.update(cx, |editor, cx| { let (range, new_name) = editor.take_rename(cx)?; - let (buffer, position) = editor - .buffer - .read(cx) - .text_anchor_for_position(range.start.clone(), cx)?; - Some((buffer, position, new_name)) + let buffer = editor.buffer.read(cx); + let (start_buffer, start) = buffer.text_anchor_for_position(range.start.clone(), cx)?; + let (end_buffer, end) = buffer.text_anchor_for_position(range.end.clone(), cx)?; + if start_buffer == end_buffer { + Some((start_buffer, start..end, new_name)) + } else { + None + } })?; let rename = workspace.project().clone().update(cx, |project, cx| { - project.perform_rename(buffer, position, new_name.clone(), true, cx) + project.perform_rename( + buffer.clone(), + range.start.clone(), + new_name.clone(), + true, + cx, + ) }); - Some(cx.spawn(|workspace, cx| async move { + let transaction = buffer.update(cx, |buffer, cx| { + buffer.finalize_last_transaction(); + buffer.start_transaction(); + buffer.edit([range], &new_name, cx); + if buffer.end_transaction(cx).is_some() { + let transaction = buffer.finalize_last_transaction().unwrap().clone(); + buffer.forget_transaction(transaction.id); + Some(transaction) + } else { + None + } + }); + + Some(cx.spawn(|workspace, mut cx| async move { let project_transaction = rename.await?; + if let Some(transaction) = transaction { + buffer.update(&mut cx, |buffer, cx| { + buffer.push_transaction(transaction, Instant::now()); + buffer.undo(cx); + }); + } Self::open_project_transaction( editor, workspace,