Skip to content

Commit

Permalink
ssh remoting: Handle OpenNewBuffer request (#19373)
Browse files Browse the repository at this point in the history
Release Notes:

- N/A
  • Loading branch information
mrnugget authored and osiewicz committed Oct 18, 2024
1 parent c4b90ab commit af2e2a6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/remote_server/src/headless_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl HeadlessProject {
client.add_request_handler(cx.weak_model(), Self::handle_remove_worktree);

client.add_model_request_handler(Self::handle_open_buffer_by_path);
client.add_model_request_handler(Self::handle_open_new_buffer);
client.add_model_request_handler(Self::handle_find_search_candidates);
client.add_model_request_handler(Self::handle_open_server_settings);

Expand Down Expand Up @@ -363,6 +364,32 @@ impl HeadlessProject {
})
}

pub async fn handle_open_new_buffer(
this: Model<Self>,
_message: TypedEnvelope<proto::OpenNewBuffer>,
mut cx: AsyncAppContext,
) -> Result<proto::OpenBufferResponse> {
let (buffer_store, buffer) = this.update(&mut cx, |this, cx| {
let buffer_store = this.buffer_store.clone();
let buffer = this
.buffer_store
.update(cx, |buffer_store, cx| buffer_store.create_buffer(cx));
anyhow::Ok((buffer_store, buffer))
})??;

let buffer = buffer.await?;
let buffer_id = buffer.read_with(&cx, |b, _| b.remote_id())?;
buffer_store.update(&mut cx, |buffer_store, cx| {
buffer_store
.create_buffer_for_peer(&buffer, SSH_PEER_ID, cx)
.detach_and_log_err(cx);
})?;

Ok(proto::OpenBufferResponse {
buffer_id: buffer_id.to_proto(),
})
}

pub async fn handle_open_server_settings(
this: Model<Self>,
_: TypedEnvelope<proto::OpenServerSettings>,
Expand Down

0 comments on commit af2e2a6

Please sign in to comment.