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 buffer_removed(&self, buffer_id: u64, cx: &mut MutableAppContext);
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
|
|
||||||
|
fn to_proto(&self) -> rpc::proto::File;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LocalFile: File {
|
pub trait LocalFile: File {
|
||||||
|
@ -352,6 +354,7 @@ impl Buffer {
|
||||||
pub fn to_proto(&self) -> proto::Buffer {
|
pub fn to_proto(&self) -> proto::Buffer {
|
||||||
proto::Buffer {
|
proto::Buffer {
|
||||||
id: self.remote_id(),
|
id: self.remote_id(),
|
||||||
|
file: self.file.as_ref().map(|f| f.to_proto()),
|
||||||
visible_text: self.text.text(),
|
visible_text: self.text.text(),
|
||||||
deleted_text: self.text.deleted_text(),
|
deleted_text: self.text.deleted_text(),
|
||||||
undo_map: self
|
undo_map: self
|
||||||
|
|
|
@ -840,11 +840,6 @@ impl RemoteWorktree {
|
||||||
let path: Arc<Path> = Arc::from(path);
|
let path: Arc<Path> = Arc::from(path);
|
||||||
let path_string = path.to_string_lossy().to_string();
|
let path_string = path.to_string_lossy().to_string();
|
||||||
cx.spawn_weak(move |this, mut cx| async move {
|
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
|
let response = rpc
|
||||||
.request(proto::OpenBuffer {
|
.request(proto::OpenBuffer {
|
||||||
project_id,
|
project_id,
|
||||||
|
@ -856,17 +851,15 @@ impl RemoteWorktree {
|
||||||
let this = this
|
let this = this
|
||||||
.upgrade(&cx)
|
.upgrade(&cx)
|
||||||
.ok_or_else(|| anyhow!("worktree was closed"))?;
|
.ok_or_else(|| anyhow!("worktree was closed"))?;
|
||||||
let file = File {
|
let mut remote_buffer = response.buffer.ok_or_else(|| anyhow!("empty buffer"))?;
|
||||||
entry_id: Some(entry.id),
|
let file = remote_buffer
|
||||||
worktree: this.clone(),
|
.file
|
||||||
path: entry.path,
|
.take()
|
||||||
mtime: entry.mtime,
|
.map(|proto| cx.read(|cx| File::from_proto(proto, this.clone(), cx)))
|
||||||
is_local: false,
|
.transpose()?
|
||||||
};
|
.map(|file| Box::new(file) as Box<dyn language::File>);
|
||||||
let remote_buffer = response.buffer.ok_or_else(|| anyhow!("empty buffer"))?;
|
|
||||||
Ok(cx.add_model(|cx| {
|
Ok(cx.add_model(|cx| Buffer::from_proto(replica_id, remote_buffer, file, cx).unwrap()))
|
||||||
Buffer::from_proto(replica_id, remote_buffer, Some(Box::new(file)), cx).unwrap()
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1499,6 +1492,15 @@ impl language::File for File {
|
||||||
fn as_any(&self) -> &dyn Any {
|
fn as_any(&self) -> &dyn Any {
|
||||||
self
|
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 {
|
impl language::LocalFile for File {
|
||||||
|
@ -1521,6 +1523,30 @@ impl language::LocalFile for File {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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> {
|
pub fn from_dyn(file: Option<&dyn language::File>) -> Option<&Self> {
|
||||||
file.and_then(|f| f.as_any().downcast_ref())
|
file.and_then(|f| f.as_any().downcast_ref())
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,25 +33,26 @@ message Envelope {
|
||||||
OpenBufferResponse open_buffer_response = 25;
|
OpenBufferResponse open_buffer_response = 25;
|
||||||
CloseBuffer close_buffer = 26;
|
CloseBuffer close_buffer = 26;
|
||||||
UpdateBuffer update_buffer = 27;
|
UpdateBuffer update_buffer = 27;
|
||||||
SaveBuffer save_buffer = 28;
|
UpdateBufferFile update_buffer_file = 28;
|
||||||
BufferSaved buffer_saved = 29;
|
SaveBuffer save_buffer = 29;
|
||||||
FormatBuffer format_buffer = 30;
|
BufferSaved buffer_saved = 30;
|
||||||
|
FormatBuffer format_buffer = 31;
|
||||||
|
|
||||||
GetChannels get_channels = 31;
|
GetChannels get_channels = 32;
|
||||||
GetChannelsResponse get_channels_response = 32;
|
GetChannelsResponse get_channels_response = 33;
|
||||||
JoinChannel join_channel = 33;
|
JoinChannel join_channel = 34;
|
||||||
JoinChannelResponse join_channel_response = 34;
|
JoinChannelResponse join_channel_response = 35;
|
||||||
LeaveChannel leave_channel = 35;
|
LeaveChannel leave_channel = 36;
|
||||||
SendChannelMessage send_channel_message = 36;
|
SendChannelMessage send_channel_message = 37;
|
||||||
SendChannelMessageResponse send_channel_message_response = 37;
|
SendChannelMessageResponse send_channel_message_response = 38;
|
||||||
ChannelMessageSent channel_message_sent = 38;
|
ChannelMessageSent channel_message_sent = 39;
|
||||||
GetChannelMessages get_channel_messages = 39;
|
GetChannelMessages get_channel_messages = 40;
|
||||||
GetChannelMessagesResponse get_channel_messages_response = 40;
|
GetChannelMessagesResponse get_channel_messages_response = 41;
|
||||||
|
|
||||||
UpdateContacts update_contacts = 41;
|
UpdateContacts update_contacts = 42;
|
||||||
|
|
||||||
GetUsers get_users = 42;
|
GetUsers get_users = 43;
|
||||||
GetUsersResponse get_users_response = 43;
|
GetUsersResponse get_users_response = 44;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +89,9 @@ message JoinProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
message JoinProjectResponse {
|
message JoinProjectResponse {
|
||||||
uint32 replica_id = 2;
|
uint32 replica_id = 1;
|
||||||
repeated Worktree worktrees = 3;
|
repeated Worktree worktrees = 2;
|
||||||
repeated Collaborator collaborators = 4;
|
repeated Collaborator collaborators = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LeaveProject {
|
message LeaveProject {
|
||||||
|
@ -150,7 +151,13 @@ message CloseBuffer {
|
||||||
message UpdateBuffer {
|
message UpdateBuffer {
|
||||||
uint64 project_id = 1;
|
uint64 project_id = 1;
|
||||||
uint64 buffer_id = 2;
|
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 {
|
message SaveBuffer {
|
||||||
|
@ -177,11 +184,11 @@ message UpdateDiagnosticSummary {
|
||||||
}
|
}
|
||||||
|
|
||||||
message DiagnosticSummary {
|
message DiagnosticSummary {
|
||||||
string path = 3;
|
string path = 1;
|
||||||
uint32 error_count = 4;
|
uint32 error_count = 2;
|
||||||
uint32 warning_count = 5;
|
uint32 warning_count = 3;
|
||||||
uint32 info_count = 6;
|
uint32 info_count = 4;
|
||||||
uint32 hint_count = 7;
|
uint32 hint_count = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DiskBasedDiagnosticsUpdating {
|
message DiskBasedDiagnosticsUpdating {
|
||||||
|
@ -272,7 +279,7 @@ message Worktree {
|
||||||
|
|
||||||
message File {
|
message File {
|
||||||
uint64 worktree_id = 1;
|
uint64 worktree_id = 1;
|
||||||
uint64 entry_id = 2;
|
optional uint64 entry_id = 2;
|
||||||
string path = 3;
|
string path = 3;
|
||||||
Timestamp mtime = 4;
|
Timestamp mtime = 4;
|
||||||
}
|
}
|
||||||
|
@ -289,15 +296,16 @@ message Entry {
|
||||||
|
|
||||||
message Buffer {
|
message Buffer {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
string visible_text = 2;
|
optional File file = 2;
|
||||||
string deleted_text = 3;
|
string visible_text = 3;
|
||||||
repeated BufferFragment fragments = 4;
|
string deleted_text = 4;
|
||||||
repeated UndoMapEntry undo_map = 5;
|
repeated BufferFragment fragments = 5;
|
||||||
repeated VectorClockEntry version = 6;
|
repeated UndoMapEntry undo_map = 6;
|
||||||
repeated SelectionSet selections = 7;
|
repeated VectorClockEntry version = 7;
|
||||||
repeated Diagnostic diagnostics = 8;
|
repeated SelectionSet selections = 8;
|
||||||
uint32 lamport_timestamp = 9;
|
repeated Diagnostic diagnostics = 9;
|
||||||
repeated Operation deferred_operations = 10;
|
uint32 lamport_timestamp = 10;
|
||||||
|
repeated Operation deferred_operations = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
message BufferFragment {
|
message BufferFragment {
|
||||||
|
@ -390,8 +398,8 @@ message Operation {
|
||||||
|
|
||||||
message UpdateSelections {
|
message UpdateSelections {
|
||||||
uint32 replica_id = 1;
|
uint32 replica_id = 1;
|
||||||
uint32 lamport_timestamp = 3;
|
uint32 lamport_timestamp = 2;
|
||||||
repeated Selection selections = 4;
|
repeated Selection selections = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,7 @@ messages!(
|
||||||
UnregisterWorktree,
|
UnregisterWorktree,
|
||||||
UnshareProject,
|
UnshareProject,
|
||||||
UpdateBuffer,
|
UpdateBuffer,
|
||||||
|
UpdateBufferFile,
|
||||||
UpdateContacts,
|
UpdateContacts,
|
||||||
UpdateDiagnosticSummary,
|
UpdateDiagnosticSummary,
|
||||||
UpdateWorktree,
|
UpdateWorktree,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue