Relay saved version metadata to ensure buffers modified state converges

This commit is contained in:
Antonio Scandurra 2023-01-17 16:20:50 +01:00
parent 2cd9db1cfe
commit bb200aa082
3 changed files with 26 additions and 2 deletions

View file

@ -385,6 +385,7 @@ impl Buffer {
rpc::proto::LineEnding::from_i32(message.line_ending) rpc::proto::LineEnding::from_i32(message.line_ending)
.ok_or_else(|| anyhow!("missing line_ending"))?, .ok_or_else(|| anyhow!("missing line_ending"))?,
)); ));
this.saved_version = proto::deserialize_version(message.saved_version);
this.saved_version_fingerprint = message.saved_version_fingerprint; this.saved_version_fingerprint = message.saved_version_fingerprint;
this.saved_mtime = message this.saved_mtime = message
.saved_mtime .saved_mtime
@ -400,6 +401,7 @@ impl Buffer {
base_text: self.base_text().to_string(), base_text: self.base_text().to_string(),
diff_base: self.diff_base.as_ref().map(|h| h.to_string()), diff_base: self.diff_base.as_ref().map(|h| h.to_string()),
line_ending: proto::serialize_line_ending(self.line_ending()) as i32, line_ending: proto::serialize_line_ending(self.line_ending()) as i32,
saved_version: proto::serialize_version(&self.saved_version),
saved_version_fingerprint: self.saved_version_fingerprint.clone(), saved_version_fingerprint: self.saved_version_fingerprint.clone(),
saved_mtime: Some(self.saved_mtime.into()), saved_mtime: Some(self.saved_mtime.into()),
} }
@ -556,6 +558,14 @@ impl Buffer {
&self.saved_version &self.saved_version
} }
pub fn saved_version_fingerprint(&self) -> &str {
&self.saved_version_fingerprint
}
pub fn saved_mtime(&self) -> SystemTime {
self.saved_mtime
}
pub fn set_language(&mut self, language: Option<Arc<Language>>, cx: &mut ModelContext<Self>) { pub fn set_language(&mut self, language: Option<Arc<Language>>, cx: &mut ModelContext<Self>) {
self.syntax_map.lock().clear(); self.syntax_map.lock().clear();
self.language = language; self.language = language;

View file

@ -5209,6 +5209,19 @@ impl Project {
}) })
.log_err(); .log_err();
client
.send(proto::BufferReloaded {
project_id,
buffer_id,
version: language::proto::serialize_version(buffer.saved_version()),
mtime: Some(buffer.saved_mtime().into()),
fingerprint: buffer.saved_version_fingerprint().into(),
line_ending: language::proto::serialize_line_ending(
buffer.line_ending(),
) as i32,
})
.log_err();
cx.background() cx.background()
.spawn( .spawn(
async move { async move {

View file

@ -975,8 +975,9 @@ message BufferState {
string base_text = 3; string base_text = 3;
optional string diff_base = 4; optional string diff_base = 4;
LineEnding line_ending = 5; LineEnding line_ending = 5;
string saved_version_fingerprint = 6; repeated VectorClockEntry saved_version = 6;
Timestamp saved_mtime = 7; string saved_version_fingerprint = 7;
Timestamp saved_mtime = 8;
} }
message BufferChunk { message BufferChunk {