mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 13:10:54 +00:00
Send File protos as part of Buffer protos
Use the File proto to build the File associated with the buffer rather than relying on the local entry.
This commit is contained in:
parent
66fce5ec8e
commit
da13d028a3
4 changed files with 92 additions and 54 deletions
|
@ -189,6 +189,8 @@ pub trait File {
|
|||
fn buffer_removed(&self, buffer_id: u64, cx: &mut MutableAppContext);
|
||||
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
|
||||
fn to_proto(&self) -> rpc::proto::File;
|
||||
}
|
||||
|
||||
pub trait LocalFile: File {
|
||||
|
@ -352,6 +354,7 @@ impl Buffer {
|
|||
pub fn to_proto(&self) -> proto::Buffer {
|
||||
proto::Buffer {
|
||||
id: self.remote_id(),
|
||||
file: self.file.as_ref().map(|f| f.to_proto()),
|
||||
visible_text: self.text.text(),
|
||||
deleted_text: self.text.deleted_text(),
|
||||
undo_map: self
|
||||
|
|
|
@ -840,11 +840,6 @@ impl RemoteWorktree {
|
|||
let path: Arc<Path> = Arc::from(path);
|
||||
let path_string = path.to_string_lossy().to_string();
|
||||
cx.spawn_weak(move |this, mut cx| async move {
|
||||
let entry = this
|
||||
.upgrade(&cx)
|
||||
.ok_or_else(|| anyhow!("worktree was closed"))?
|
||||
.read_with(&cx, |tree, _| tree.entry_for_path(&path).cloned())
|
||||
.ok_or_else(|| anyhow!("file does not exist"))?;
|
||||
let response = rpc
|
||||
.request(proto::OpenBuffer {
|
||||
project_id,
|
||||
|
@ -856,17 +851,15 @@ impl RemoteWorktree {
|
|||
let this = this
|
||||
.upgrade(&cx)
|
||||
.ok_or_else(|| anyhow!("worktree was closed"))?;
|
||||
let file = File {
|
||||
entry_id: Some(entry.id),
|
||||
worktree: this.clone(),
|
||||
path: entry.path,
|
||||
mtime: entry.mtime,
|
||||
is_local: false,
|
||||
};
|
||||
let remote_buffer = response.buffer.ok_or_else(|| anyhow!("empty buffer"))?;
|
||||
Ok(cx.add_model(|cx| {
|
||||
Buffer::from_proto(replica_id, remote_buffer, Some(Box::new(file)), cx).unwrap()
|
||||
}))
|
||||
let mut remote_buffer = response.buffer.ok_or_else(|| anyhow!("empty buffer"))?;
|
||||
let file = remote_buffer
|
||||
.file
|
||||
.take()
|
||||
.map(|proto| cx.read(|cx| File::from_proto(proto, this.clone(), cx)))
|
||||
.transpose()?
|
||||
.map(|file| Box::new(file) as Box<dyn language::File>);
|
||||
|
||||
Ok(cx.add_model(|cx| Buffer::from_proto(replica_id, remote_buffer, file, cx).unwrap()))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1499,6 +1492,15 @@ impl language::File for File {
|
|||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn to_proto(&self) -> rpc::proto::File {
|
||||
rpc::proto::File {
|
||||
worktree_id: self.worktree.id() as u64,
|
||||
entry_id: self.entry_id.map(|entry_id| entry_id as u64),
|
||||
path: self.path.to_string_lossy().into(),
|
||||
mtime: Some(self.mtime.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl language::LocalFile for File {
|
||||
|
@ -1521,6 +1523,30 @@ impl language::LocalFile for File {
|
|||
}
|
||||
|
||||
impl File {
|
||||
pub fn from_proto(
|
||||
proto: rpc::proto::File,
|
||||
worktree: ModelHandle<Worktree>,
|
||||
cx: &AppContext,
|
||||
) -> Result<Self> {
|
||||
let worktree_id = worktree
|
||||
.read(cx)
|
||||
.as_remote()
|
||||
.ok_or_else(|| anyhow!("not remote"))?
|
||||
.id();
|
||||
|
||||
if worktree_id.to_proto() != proto.worktree_id {
|
||||
return Err(anyhow!("worktree id does not match file"));
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
worktree,
|
||||
path: Path::new(&proto.path).into(),
|
||||
mtime: proto.mtime.ok_or_else(|| anyhow!("no timestamp"))?.into(),
|
||||
entry_id: proto.entry_id.map(|entry_id| entry_id as usize),
|
||||
is_local: false,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn from_dyn(file: Option<&dyn language::File>) -> Option<&Self> {
|
||||
file.and_then(|f| f.as_any().downcast_ref())
|
||||
}
|
||||
|
|
|
@ -33,25 +33,26 @@ message Envelope {
|
|||
OpenBufferResponse open_buffer_response = 25;
|
||||
CloseBuffer close_buffer = 26;
|
||||
UpdateBuffer update_buffer = 27;
|
||||
SaveBuffer save_buffer = 28;
|
||||
BufferSaved buffer_saved = 29;
|
||||
FormatBuffer format_buffer = 30;
|
||||
UpdateBufferFile update_buffer_file = 28;
|
||||
SaveBuffer save_buffer = 29;
|
||||
BufferSaved buffer_saved = 30;
|
||||
FormatBuffer format_buffer = 31;
|
||||
|
||||
GetChannels get_channels = 31;
|
||||
GetChannelsResponse get_channels_response = 32;
|
||||
JoinChannel join_channel = 33;
|
||||
JoinChannelResponse join_channel_response = 34;
|
||||
LeaveChannel leave_channel = 35;
|
||||
SendChannelMessage send_channel_message = 36;
|
||||
SendChannelMessageResponse send_channel_message_response = 37;
|
||||
ChannelMessageSent channel_message_sent = 38;
|
||||
GetChannelMessages get_channel_messages = 39;
|
||||
GetChannelMessagesResponse get_channel_messages_response = 40;
|
||||
GetChannels get_channels = 32;
|
||||
GetChannelsResponse get_channels_response = 33;
|
||||
JoinChannel join_channel = 34;
|
||||
JoinChannelResponse join_channel_response = 35;
|
||||
LeaveChannel leave_channel = 36;
|
||||
SendChannelMessage send_channel_message = 37;
|
||||
SendChannelMessageResponse send_channel_message_response = 38;
|
||||
ChannelMessageSent channel_message_sent = 39;
|
||||
GetChannelMessages get_channel_messages = 40;
|
||||
GetChannelMessagesResponse get_channel_messages_response = 41;
|
||||
|
||||
UpdateContacts update_contacts = 41;
|
||||
UpdateContacts update_contacts = 42;
|
||||
|
||||
GetUsers get_users = 42;
|
||||
GetUsersResponse get_users_response = 43;
|
||||
GetUsers get_users = 43;
|
||||
GetUsersResponse get_users_response = 44;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,9 +89,9 @@ message JoinProject {
|
|||
}
|
||||
|
||||
message JoinProjectResponse {
|
||||
uint32 replica_id = 2;
|
||||
repeated Worktree worktrees = 3;
|
||||
repeated Collaborator collaborators = 4;
|
||||
uint32 replica_id = 1;
|
||||
repeated Worktree worktrees = 2;
|
||||
repeated Collaborator collaborators = 3;
|
||||
}
|
||||
|
||||
message LeaveProject {
|
||||
|
@ -150,7 +151,13 @@ message CloseBuffer {
|
|||
message UpdateBuffer {
|
||||
uint64 project_id = 1;
|
||||
uint64 buffer_id = 2;
|
||||
repeated Operation operations = 4;
|
||||
repeated Operation operations = 3;
|
||||
}
|
||||
|
||||
message UpdateBufferFile {
|
||||
uint64 project_id = 1;
|
||||
uint64 buffer_id = 2;
|
||||
File file = 3;
|
||||
}
|
||||
|
||||
message SaveBuffer {
|
||||
|
@ -177,11 +184,11 @@ message UpdateDiagnosticSummary {
|
|||
}
|
||||
|
||||
message DiagnosticSummary {
|
||||
string path = 3;
|
||||
uint32 error_count = 4;
|
||||
uint32 warning_count = 5;
|
||||
uint32 info_count = 6;
|
||||
uint32 hint_count = 7;
|
||||
string path = 1;
|
||||
uint32 error_count = 2;
|
||||
uint32 warning_count = 3;
|
||||
uint32 info_count = 4;
|
||||
uint32 hint_count = 5;
|
||||
}
|
||||
|
||||
message DiskBasedDiagnosticsUpdating {
|
||||
|
@ -272,7 +279,7 @@ message Worktree {
|
|||
|
||||
message File {
|
||||
uint64 worktree_id = 1;
|
||||
uint64 entry_id = 2;
|
||||
optional uint64 entry_id = 2;
|
||||
string path = 3;
|
||||
Timestamp mtime = 4;
|
||||
}
|
||||
|
@ -289,15 +296,16 @@ message Entry {
|
|||
|
||||
message Buffer {
|
||||
uint64 id = 1;
|
||||
string visible_text = 2;
|
||||
string deleted_text = 3;
|
||||
repeated BufferFragment fragments = 4;
|
||||
repeated UndoMapEntry undo_map = 5;
|
||||
repeated VectorClockEntry version = 6;
|
||||
repeated SelectionSet selections = 7;
|
||||
repeated Diagnostic diagnostics = 8;
|
||||
uint32 lamport_timestamp = 9;
|
||||
repeated Operation deferred_operations = 10;
|
||||
optional File file = 2;
|
||||
string visible_text = 3;
|
||||
string deleted_text = 4;
|
||||
repeated BufferFragment fragments = 5;
|
||||
repeated UndoMapEntry undo_map = 6;
|
||||
repeated VectorClockEntry version = 7;
|
||||
repeated SelectionSet selections = 8;
|
||||
repeated Diagnostic diagnostics = 9;
|
||||
uint32 lamport_timestamp = 10;
|
||||
repeated Operation deferred_operations = 11;
|
||||
}
|
||||
|
||||
message BufferFragment {
|
||||
|
@ -306,7 +314,7 @@ message BufferFragment {
|
|||
uint32 lamport_timestamp = 3;
|
||||
uint32 insertion_offset = 4;
|
||||
uint32 len = 5;
|
||||
bool visible = 6;
|
||||
bool visible = 6;
|
||||
repeated VectorClockEntry deletions = 7;
|
||||
repeated VectorClockEntry max_undos = 8;
|
||||
}
|
||||
|
@ -390,8 +398,8 @@ message Operation {
|
|||
|
||||
message UpdateSelections {
|
||||
uint32 replica_id = 1;
|
||||
uint32 lamport_timestamp = 3;
|
||||
repeated Selection selections = 4;
|
||||
uint32 lamport_timestamp = 2;
|
||||
repeated Selection selections = 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ messages!(
|
|||
UnregisterWorktree,
|
||||
UnshareProject,
|
||||
UpdateBuffer,
|
||||
UpdateBufferFile,
|
||||
UpdateContacts,
|
||||
UpdateDiagnosticSummary,
|
||||
UpdateWorktree,
|
||||
|
|
Loading…
Reference in a new issue