mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-26 18:41:10 +00:00
WIP
This commit is contained in:
parent
2841605328
commit
d705244210
2 changed files with 54 additions and 17 deletions
|
@ -817,19 +817,28 @@ impl Client {
|
||||||
self.peer.send(self.connection_id()?, message)
|
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!(
|
log::debug!(
|
||||||
"rpc request start. client_id: {}. name:{}",
|
"rpc request start. client_id: {}. name:{}",
|
||||||
self.id,
|
client_id,
|
||||||
T::NAME
|
T::NAME
|
||||||
);
|
);
|
||||||
let response = self.peer.request(self.connection_id()?, request).await;
|
let response = self
|
||||||
log::debug!(
|
.connection_id()
|
||||||
"rpc request finish. client_id: {}. name:{}",
|
.map(|conn_id| self.peer.request(conn_id, request));
|
||||||
self.id,
|
async move {
|
||||||
T::NAME
|
let response = response?.await;
|
||||||
);
|
log::debug!(
|
||||||
response
|
"rpc request finish. client_id: {}. name:{}",
|
||||||
|
client_id,
|
||||||
|
T::NAME
|
||||||
|
);
|
||||||
|
response
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn respond<T: RequestMessage>(&self, receipt: Receipt<T>, response: T::Response) -> Result<()> {
|
fn respond<T: RequestMessage>(&self, receipt: Receipt<T>, response: T::Response) -> Result<()> {
|
||||||
|
|
|
@ -4146,21 +4146,49 @@ impl Editor {
|
||||||
) -> Option<Task<Result<()>>> {
|
) -> Option<Task<Result<()>>> {
|
||||||
let editor = workspace.active_item(cx)?.act_as::<Editor>(cx)?;
|
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 (range, new_name) = editor.take_rename(cx)?;
|
||||||
let (buffer, position) = editor
|
let buffer = editor.buffer.read(cx);
|
||||||
.buffer
|
let (start_buffer, start) = buffer.text_anchor_for_position(range.start.clone(), cx)?;
|
||||||
.read(cx)
|
let (end_buffer, end) = buffer.text_anchor_for_position(range.end.clone(), cx)?;
|
||||||
.text_anchor_for_position(range.start.clone(), cx)?;
|
if start_buffer == end_buffer {
|
||||||
Some((buffer, position, new_name))
|
Some((start_buffer, start..end, new_name))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let rename = workspace.project().clone().update(cx, |project, cx| {
|
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?;
|
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(
|
Self::open_project_transaction(
|
||||||
editor,
|
editor,
|
||||||
workspace,
|
workspace,
|
||||||
|
|
Loading…
Reference in a new issue