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
|
@ -1429,21 +1429,23 @@ impl Project {
|
|||
}
|
||||
|
||||
pub fn save_buffers(
|
||||
&self,
|
||||
buffers: HashSet<ModelHandle<Buffer>>,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
cx.spawn(|mut cx| async move {
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let save_tasks = buffers
|
||||
.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?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn save_buffer(
|
||||
&self,
|
||||
buffer: ModelHandle<Buffer>,
|
||||
cx: &mut MutableAppContext,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<(clock::Global, RopeFingerprint, SystemTime)>> {
|
||||
let Some(file) = File::from_dyn(buffer.read(cx).file()) else {
|
||||
return Task::ready(Err(anyhow!("buffer doesn't have a file")));
|
||||
|
@ -1460,7 +1462,7 @@ impl Project {
|
|||
&mut self,
|
||||
buffer: ModelHandle<Buffer>,
|
||||
abs_path: PathBuf,
|
||||
cx: &mut ModelContext<Project>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<()>> {
|
||||
let worktree_task = self.find_or_create_local_worktree(&abs_path, true, cx);
|
||||
let old_path =
|
||||
|
@ -5186,8 +5188,9 @@ impl Project {
|
|||
})
|
||||
.await;
|
||||
|
||||
let (saved_version, fingerprint, mtime) =
|
||||
cx.update(|cx| Self::save_buffer(buffer, cx)).await?;
|
||||
let (saved_version, fingerprint, mtime) = this
|
||||
.update(&mut cx, |this, cx| this.save_buffer(buffer, cx))
|
||||
.await?;
|
||||
Ok(proto::BufferSaved {
|
||||
project_id,
|
||||
buffer_id,
|
||||
|
|
|
@ -243,7 +243,8 @@ async fn test_managing_language_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
|
||||
.unwrap();
|
||||
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);
|
||||
});
|
||||
|
||||
cx.update(|cx| Project::save_buffer(buffer.clone(), cx))
|
||||
project
|
||||
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
|
||||
.await
|
||||
.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);
|
||||
});
|
||||
|
||||
cx.update(|cx| Project::save_buffer(buffer.clone(), cx))
|
||||
project
|
||||
.update(cx, |project, cx| project.save_buffer(buffer.clone(), cx))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -2704,7 +2707,8 @@ async fn test_buffer_line_endings(cx: &mut gpui::TestAppContext) {
|
|||
buffer2.update(cx, |buffer, 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
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue