Make Project::save_buffer and ::save_buffers into methods
This commit is contained in:
parent
56b7eb6b6f
commit
010eba509c
5 changed files with 25 additions and 16 deletions
|
@ -2244,7 +2244,7 @@ async fn test_propagate_saves_and_fs_changes(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Edit the buffer as the host and concurrently save as guest B.
|
// Edit the buffer as the host and concurrently save as guest B.
|
||||||
let save_b = cx_b.update(|cx| Project::save_buffer(buffer_b.clone(), cx));
|
let save_b = project_b.update(cx_b, |project, cx| project.save_buffer(buffer_b.clone(), cx));
|
||||||
buffer_a.update(cx_a, |buf, cx| buf.edit([(0..0, "hi-a, ")], None, cx));
|
buffer_a.update(cx_a, |buf, cx| buf.edit([(0..0, "hi-a, ")], None, cx));
|
||||||
save_b.await.unwrap();
|
save_b.await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2917,7 +2917,7 @@ async fn test_buffer_conflict_after_save(
|
||||||
assert!(!buf.has_conflict());
|
assert!(!buf.has_conflict());
|
||||||
});
|
});
|
||||||
|
|
||||||
cx_b.update(|cx| Project::save_buffer(buffer_b.clone(), cx))
|
project_b.update(cx_b, |project, cx| project.save_buffer(buffer_b.clone(), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cx_a.foreground().forbid_parking();
|
cx_a.foreground().forbid_parking();
|
||||||
|
|
|
@ -1073,7 +1073,7 @@ async fn randomly_query_and_mutate_buffers(
|
||||||
);
|
);
|
||||||
buffer.version()
|
buffer.version()
|
||||||
});
|
});
|
||||||
let save = cx.update(|cx| Project::save_buffer(buffer, cx));
|
let save = project.update(cx, |project, cx| project.save_buffer(buffer, cx));
|
||||||
let save = cx.background().spawn(async move {
|
let save = cx.background().spawn(async move {
|
||||||
let (saved_version, _, _) = save
|
let (saved_version, _, _) = save
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -610,9 +610,11 @@ impl Item for Editor {
|
||||||
self.report_event("save editor", cx);
|
self.report_event("save editor", cx);
|
||||||
let format = self.perform_format(project.clone(), cx);
|
let format = self.perform_format(project.clone(), cx);
|
||||||
let buffers = self.buffer().clone().read(cx).all_buffers();
|
let buffers = self.buffer().clone().read(cx).all_buffers();
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.as_mut().spawn(|mut cx| async move {
|
||||||
format.await?;
|
format.await?;
|
||||||
cx.update(|cx| Project::save_buffers(buffers, cx)).await?;
|
project
|
||||||
|
.update(&mut cx, |project, cx| project.save_buffers(buffers, cx))
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1429,21 +1429,23 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_buffers(
|
pub fn save_buffers(
|
||||||
|
&self,
|
||||||
buffers: HashSet<ModelHandle<Buffer>>,
|
buffers: HashSet<ModelHandle<Buffer>>,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let save_tasks = buffers
|
let save_tasks = buffers
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|buffer| cx.update(|cx| Self::save_buffer(buffer, cx)));
|
.map(|buffer| this.update(&mut cx, |this, cx| this.save_buffer(buffer, cx)));
|
||||||
try_join_all(save_tasks).await?;
|
try_join_all(save_tasks).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save_buffer(
|
pub fn save_buffer(
|
||||||
|
&self,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer: ModelHandle<Buffer>,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<(clock::Global, RopeFingerprint, SystemTime)>> {
|
) -> Task<Result<(clock::Global, RopeFingerprint, SystemTime)>> {
|
||||||
let Some(file) = File::from_dyn(buffer.read(cx).file()) else {
|
let Some(file) = File::from_dyn(buffer.read(cx).file()) else {
|
||||||
return Task::ready(Err(anyhow!("buffer doesn't have a file")));
|
return Task::ready(Err(anyhow!("buffer doesn't have a file")));
|
||||||
|
@ -1460,7 +1462,7 @@ impl Project {
|
||||||
&mut self,
|
&mut self,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer: ModelHandle<Buffer>,
|
||||||
abs_path: PathBuf,
|
abs_path: PathBuf,
|
||||||
cx: &mut ModelContext<Project>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
let worktree_task = self.find_or_create_local_worktree(&abs_path, true, cx);
|
let worktree_task = self.find_or_create_local_worktree(&abs_path, true, cx);
|
||||||
let old_path =
|
let old_path =
|
||||||
|
@ -5186,8 +5188,9 @@ impl Project {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let (saved_version, fingerprint, mtime) =
|
let (saved_version, fingerprint, mtime) = this
|
||||||
cx.update(|cx| Self::save_buffer(buffer, cx)).await?;
|
.update(&mut cx, |this, cx| this.save_buffer(buffer, cx))
|
||||||
|
.await?;
|
||||||
Ok(proto::BufferSaved {
|
Ok(proto::BufferSaved {
|
||||||
project_id,
|
project_id,
|
||||||
buffer_id,
|
buffer_id,
|
||||||
|
|
|
@ -243,7 +243,8 @@ async fn test_managing_language_servers(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Save notifications are reported to all servers.
|
// Save notifications are reported to all servers.
|
||||||
cx.update(|cx| Project::save_buffer(toml_buffer, cx))
|
project
|
||||||
|
.update(cx, |project, cx| project.save_buffer(toml_buffer, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2087,7 +2088,8 @@ async fn test_save_file(cx: &mut gpui::TestAppContext) {
|
||||||
buffer.edit([(0..0, "a line of text.\n".repeat(10 * 1024))], None, cx);
|
buffer.edit([(0..0, "a line of text.\n".repeat(10 * 1024))], None, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.update(|cx| Project::save_buffer(buffer.clone(), cx))
|
project
|
||||||
|
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -2115,7 +2117,8 @@ async fn test_save_in_single_file_worktree(cx: &mut gpui::TestAppContext) {
|
||||||
buffer.edit([(0..0, "a line of text.\n".repeat(10 * 1024))], None, cx);
|
buffer.edit([(0..0, "a line of text.\n".repeat(10 * 1024))], None, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.update(|cx| Project::save_buffer(buffer.clone(), cx))
|
project
|
||||||
|
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -2704,7 +2707,8 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) {
|
||||||
buffer2.update(cx, |buffer, cx| {
|
buffer2.update(cx, |buffer, cx| {
|
||||||
buffer.set_text("one\ntwo\nthree\nfour\n", cx);
|
buffer.set_text("one\ntwo\nthree\nfour\n", cx);
|
||||||
});
|
});
|
||||||
cx.update(|cx| Project::save_buffer(buffer2, cx))
|
project
|
||||||
|
.update(cx, |project, cx| project.save_buffer(buffer2, cx))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue