Redesign Worktree save API and make test_rescan_simple pass

This commit does too much. The first goal was to change our approach to saving new buffers so that we don't need to construct a File for an entry that doesn't exist. Rather than doing that, we call `Worktree::save_buffer_as` with the buffer handle, the path, and the contents. This then saves the buffer and returns a handle to a `File` that references an entry that actually exists. I needed to do this so that we can store an entry id on `File`.

In the process, I noticed intermittent test failures on `test_rescan_simple`, so I made some changes required to fix those related to our reuse of existing ids. Our previous approach of removing a path when inserting a new entry was broken, because of the recursive nature of `remove_path`. Instead, I simply recycle the id of an existing worktree entry with the same path if one is present, then allow it to be replaced.
This commit is contained in:
Nathan Sobo
2021-06-28 19:05:38 -06:00
parent 1793eda470
commit b7a4393f29
4 changed files with 190 additions and 108 deletions
+13 -3
View File
@@ -7,7 +7,7 @@ use crate::{
settings::{Settings, StyleId},
util::{post_inc, Bias},
workspace,
worktree::File,
worktree::{File, Worktree},
};
use anyhow::Result;
pub use buffer::*;
@@ -2506,8 +2506,18 @@ impl workspace::ItemView for Editor {
Some(clone)
}
fn save(&mut self, new_file: Option<File>, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
self.buffer.update(cx, |b, cx| b.save(new_file, cx))
fn save(&mut self, cx: &mut ViewContext<Self>) -> Result<Task<Result<()>>> {
self.buffer.update(cx, |b, cx| b.save(cx))
}
fn save_as(
&mut self,
worktree: &ModelHandle<Worktree>,
path: &Path,
cx: &mut ViewContext<Self>,
) -> Task<Result<()>> {
self.buffer
.update(cx, |b, cx| b.save_as(worktree, path, cx))
}
fn is_dirty(&self, cx: &AppContext) -> bool {