Don't autosave unmodified buffers (#32626)

Closes https://github.com/zed-industries/zed/issues/12091

Proper redo of https://github.com/zed-industries/zed/pull/32603

Release Notes:

- Fixed formatting effects not triggered when saving unmodified
singleton buffers

---------

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Cole Miller <m@cole-miller.net>
This commit is contained in:
Kirill Bulatov 2025-06-13 01:12:14 +03:00 committed by GitHub
parent cd018da1ad
commit cef0c415f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 453 additions and 171 deletions

View file

@ -897,6 +897,7 @@ struct FakeFsState {
buffered_events: Vec<PathEvent>,
metadata_call_count: usize,
read_dir_call_count: usize,
path_write_counts: std::collections::HashMap<PathBuf, usize>,
moves: std::collections::HashMap<u64, PathBuf>,
home_dir: Option<PathBuf>,
}
@ -1083,6 +1084,7 @@ impl FakeFs {
events_paused: false,
read_dir_call_count: 0,
metadata_call_count: 0,
path_write_counts: Default::default(),
moves: Default::default(),
home_dir: None,
})),
@ -1173,6 +1175,8 @@ impl FakeFs {
recreate_inode: bool,
) -> Result<()> {
let mut state = self.state.lock();
let path_buf = path.as_ref().to_path_buf();
*state.path_write_counts.entry(path_buf).or_insert(0) += 1;
let new_inode = state.get_and_increment_inode();
let new_mtime = state.get_and_increment_mtime();
let new_len = new_content.len() as u64;
@ -1727,6 +1731,17 @@ impl FakeFs {
self.state.lock().metadata_call_count
}
/// How many write operations have been issued for a specific path.
pub fn write_count_for_path(&self, path: impl AsRef<Path>) -> usize {
let path = path.as_ref().to_path_buf();
self.state
.lock()
.path_write_counts
.get(&path)
.copied()
.unwrap_or(0)
}
fn simulate_random_delay(&self) -> impl futures::Future<Output = ()> {
self.executor.simulate_random_delay()
}