Only send UpdateBufferFile messages for buffers whose files have changed
Send that message when saving a buffer as a new path.
This commit is contained in:
parent
cdf64b6cad
commit
56b7eb6b6f
4 changed files with 43 additions and 36 deletions
|
@ -549,16 +549,11 @@ impl Buffer {
|
||||||
version: clock::Global,
|
version: clock::Global,
|
||||||
fingerprint: RopeFingerprint,
|
fingerprint: RopeFingerprint,
|
||||||
mtime: SystemTime,
|
mtime: SystemTime,
|
||||||
new_file: Option<Arc<dyn File>>,
|
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.saved_version = version;
|
self.saved_version = version;
|
||||||
self.saved_version_fingerprint = fingerprint;
|
self.saved_version_fingerprint = fingerprint;
|
||||||
self.saved_mtime = mtime;
|
self.saved_mtime = mtime;
|
||||||
if let Some(new_file) = new_file {
|
|
||||||
self.file = Some(new_file);
|
|
||||||
self.file_update_count += 1;
|
|
||||||
}
|
|
||||||
cx.emit(Event::Saved);
|
cx.emit(Event::Saved);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4461,6 +4461,7 @@ impl Project {
|
||||||
renamed_buffers.push((cx.handle(), old_path));
|
renamed_buffers.push((cx.handle(), old_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if new_file != *old_file {
|
||||||
if let Some(project_id) = self.remote_id() {
|
if let Some(project_id) = self.remote_id() {
|
||||||
self.client
|
self.client
|
||||||
.send(proto::UpdateBufferFile {
|
.send(proto::UpdateBufferFile {
|
||||||
|
@ -4470,8 +4471,10 @@ impl Project {
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.file_updated(Arc::new(new_file), cx).detach();
|
buffer.file_updated(Arc::new(new_file), cx).detach();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
buffers_to_delete.push(*buffer_id);
|
buffers_to_delete.push(*buffer_id);
|
||||||
|
@ -6054,7 +6057,7 @@ impl Project {
|
||||||
.and_then(|buffer| buffer.upgrade(cx));
|
.and_then(|buffer| buffer.upgrade(cx));
|
||||||
if let Some(buffer) = buffer {
|
if let Some(buffer) = buffer {
|
||||||
buffer.update(cx, |buffer, cx| {
|
buffer.update(cx, |buffer, cx| {
|
||||||
buffer.did_save(version, fingerprint, mtime, None, cx);
|
buffer.did_save(version, fingerprint, mtime, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -2482,7 +2482,6 @@ async fn test_buffer_is_dirty(cx: &mut gpui::TestAppContext) {
|
||||||
buffer.version(),
|
buffer.version(),
|
||||||
buffer.as_rope().fingerprint(),
|
buffer.as_rope().fingerprint(),
|
||||||
buffer.file().unwrap().mtime(),
|
buffer.file().unwrap().mtime(),
|
||||||
None,
|
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,6 +20,7 @@ use gpui::{
|
||||||
executor, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext,
|
executor, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext,
|
||||||
Task,
|
Task,
|
||||||
};
|
};
|
||||||
|
use language::File as _;
|
||||||
use language::{
|
use language::{
|
||||||
proto::{
|
proto::{
|
||||||
deserialize_fingerprint, deserialize_version, serialize_fingerprint, serialize_line_ending,
|
deserialize_fingerprint, deserialize_version, serialize_fingerprint, serialize_line_ending,
|
||||||
|
@ -728,7 +729,7 @@ impl LocalWorktree {
|
||||||
&self,
|
&self,
|
||||||
buffer_handle: ModelHandle<Buffer>,
|
buffer_handle: ModelHandle<Buffer>,
|
||||||
path: Arc<Path>,
|
path: Arc<Path>,
|
||||||
replace_file: bool,
|
has_changed_file: bool,
|
||||||
cx: &mut ModelContext<Worktree>,
|
cx: &mut ModelContext<Worktree>,
|
||||||
) -> Task<Result<(clock::Global, RopeFingerprint, SystemTime)>> {
|
) -> Task<Result<(clock::Global, RopeFingerprint, SystemTime)>> {
|
||||||
let handle = cx.handle();
|
let handle = cx.handle();
|
||||||
|
@ -746,6 +747,32 @@ impl LocalWorktree {
|
||||||
cx.as_mut().spawn(|mut cx| async move {
|
cx.as_mut().spawn(|mut cx| async move {
|
||||||
let entry = save.await?;
|
let entry = save.await?;
|
||||||
|
|
||||||
|
if has_changed_file {
|
||||||
|
let new_file = Arc::new(File {
|
||||||
|
entry_id: entry.id,
|
||||||
|
worktree: handle,
|
||||||
|
path: entry.path,
|
||||||
|
mtime: entry.mtime,
|
||||||
|
is_local: true,
|
||||||
|
is_deleted: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(project_id) = project_id {
|
||||||
|
rpc.send(proto::UpdateBufferFile {
|
||||||
|
project_id,
|
||||||
|
buffer_id,
|
||||||
|
file: Some(new_file.to_proto()),
|
||||||
|
})
|
||||||
|
.log_err();
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_handle.update(&mut cx, |buffer, cx| {
|
||||||
|
if has_changed_file {
|
||||||
|
buffer.file_updated(new_file, cx).detach();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(project_id) = project_id {
|
if let Some(project_id) = project_id {
|
||||||
rpc.send(proto::BufferSaved {
|
rpc.send(proto::BufferSaved {
|
||||||
project_id,
|
project_id,
|
||||||
|
@ -757,24 +784,7 @@ impl LocalWorktree {
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_handle.update(&mut cx, |buffer, cx| {
|
buffer_handle.update(&mut cx, |buffer, cx| {
|
||||||
buffer.did_save(
|
buffer.did_save(version.clone(), fingerprint, entry.mtime, cx);
|
||||||
version.clone(),
|
|
||||||
fingerprint,
|
|
||||||
entry.mtime,
|
|
||||||
if replace_file {
|
|
||||||
Some(Arc::new(File {
|
|
||||||
entry_id: entry.id,
|
|
||||||
worktree: handle,
|
|
||||||
path: entry.path,
|
|
||||||
mtime: entry.mtime,
|
|
||||||
is_local: true,
|
|
||||||
is_deleted: false,
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok((version, fingerprint, entry.mtime))
|
Ok((version, fingerprint, entry.mtime))
|
||||||
|
@ -1137,7 +1147,7 @@ impl RemoteWorktree {
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
buffer_handle.update(&mut cx, |buffer, cx| {
|
buffer_handle.update(&mut cx, |buffer, cx| {
|
||||||
buffer.did_save(version.clone(), fingerprint, mtime, None, cx);
|
buffer.did_save(version.clone(), fingerprint, mtime, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok((version, fingerprint, mtime))
|
Ok((version, fingerprint, mtime))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue