This commit is contained in:
Antonio Scandurra 2022-02-18 18:12:10 +01:00 committed by Max Brunsfeld
parent 2841605328
commit d705244210
2 changed files with 54 additions and 17 deletions

View File

@ -817,19 +817,28 @@ impl Client {
self.peer.send(self.connection_id()?, message)
}
pub async fn request<T: RequestMessage>(&self, request: T) -> Result<T::Response> {
pub fn request<T: RequestMessage>(
&self,
request: T,
) -> impl Future<Output = Result<T::Response>> {
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<T: RequestMessage>(&self, receipt: Receipt<T>, response: T::Response) -> Result<()> {

View File

@ -4146,21 +4146,49 @@ impl Editor {
) -> Option<Task<Result<()>>> {
let editor = workspace.active_item(cx)?.act_as::<Editor>(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,