Make git blame for SSH remote projects (#15106)
This also refactors the BufferStore + WorktreeStore interfaces to make them cleaner, more fully encapsulating the RPC aspects of their functionality. Release Notes: - N/A
This commit is contained in:
parent
8501ae6a19
commit
b14bb6bda4
6 changed files with 452 additions and 567 deletions
|
@ -40,14 +40,18 @@ impl HeadlessProject {
|
|||
let this = cx.weak_model();
|
||||
|
||||
let worktree_store = cx.new_model(|_| WorktreeStore::new(true));
|
||||
let buffer_store = cx.new_model(|cx| BufferStore::new(worktree_store.clone(), true, cx));
|
||||
let buffer_store =
|
||||
cx.new_model(|cx| BufferStore::new(worktree_store.clone(), Some(PROJECT_ID), cx));
|
||||
cx.subscribe(&buffer_store, Self::on_buffer_store_event)
|
||||
.detach();
|
||||
|
||||
session.add_request_handler(this.clone(), Self::handle_add_worktree);
|
||||
session.add_request_handler(this.clone(), Self::handle_open_buffer_by_path);
|
||||
session.add_request_handler(this.clone(), Self::handle_update_buffer);
|
||||
session.add_request_handler(this.clone(), Self::handle_save_buffer);
|
||||
|
||||
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_blame_buffer);
|
||||
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_update_buffer);
|
||||
session.add_request_handler(buffer_store.downgrade(), BufferStore::handle_save_buffer);
|
||||
|
||||
session.add_request_handler(
|
||||
worktree_store.downgrade(),
|
||||
WorktreeStore::handle_create_project_entry,
|
||||
|
@ -112,27 +116,6 @@ impl HeadlessProject {
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn handle_update_buffer(
|
||||
this: Model<Self>,
|
||||
envelope: TypedEnvelope<proto::UpdateBuffer>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::Ack> {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.buffer_store.update(cx, |buffer_store, cx| {
|
||||
buffer_store.handle_update_buffer(envelope, false, cx)
|
||||
})
|
||||
})?
|
||||
}
|
||||
|
||||
pub async fn handle_save_buffer(
|
||||
this: Model<Self>,
|
||||
envelope: TypedEnvelope<proto::SaveBuffer>,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<proto::BufferSaved> {
|
||||
let buffer_store = this.update(&mut cx, |this, _| this.buffer_store.clone())?;
|
||||
BufferStore::handle_save_buffer(buffer_store, PROJECT_ID, envelope, cx).await
|
||||
}
|
||||
|
||||
pub async fn handle_open_buffer_by_path(
|
||||
this: Model<Self>,
|
||||
message: TypedEnvelope<proto::OpenBufferByPath>,
|
||||
|
@ -178,33 +161,12 @@ impl HeadlessProject {
|
|||
&mut self,
|
||||
_: Model<BufferStore>,
|
||||
event: &BufferStoreEvent,
|
||||
cx: &mut ModelContext<Self>,
|
||||
_: &mut ModelContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
BufferStoreEvent::LocalBufferUpdated { buffer } => {
|
||||
let buffer = buffer.read(cx);
|
||||
let buffer_id = buffer.remote_id();
|
||||
let Some(new_file) = buffer.file() else {
|
||||
return;
|
||||
};
|
||||
BufferStoreEvent::MessageToReplicas(message) => {
|
||||
self.session
|
||||
.send(proto::UpdateBufferFile {
|
||||
project_id: 0,
|
||||
buffer_id: buffer_id.into(),
|
||||
file: Some(new_file.to_proto(cx)),
|
||||
})
|
||||
.log_err();
|
||||
}
|
||||
BufferStoreEvent::DiffBaseUpdated { buffer } => {
|
||||
let buffer = buffer.read(cx);
|
||||
let buffer_id = buffer.remote_id();
|
||||
let diff_base = buffer.diff_base();
|
||||
self.session
|
||||
.send(proto::UpdateDiffBase {
|
||||
project_id: 0,
|
||||
buffer_id: buffer_id.to_proto(),
|
||||
diff_base: diff_base.map(|b| b.to_string()),
|
||||
})
|
||||
.send_dynamic(message.as_ref().clone())
|
||||
.log_err();
|
||||
}
|
||||
_ => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue