Added theme and dock anchor saving :D

This commit is contained in:
Mikayla Maki 2022-10-11 19:18:29 -07:00
parent 5487f99ac7
commit e7b6d1befe
9 changed files with 111 additions and 19 deletions

View file

@ -15,6 +15,7 @@ util = { path = "../util" }
anyhow = "1.0.57"
async-trait = "0.1"
futures = "0.3"
tempfile = "3"
fsevent = { path = "../fsevent" }
lazy_static = "1.4.0"
parking_lot = "0.11.1"

View file

@ -12,6 +12,7 @@ use rope::Rope;
use smol::io::{AsyncReadExt, AsyncWriteExt};
use std::borrow::Cow;
use std::cmp;
use std::io::Write;
use std::sync::Arc;
use std::{
io,
@ -20,6 +21,7 @@ use std::{
pin::Pin,
time::{Duration, SystemTime},
};
use tempfile::NamedTempFile;
use util::ResultExt;
#[cfg(any(test, feature = "test-support"))]
@ -100,6 +102,7 @@ pub trait Fs: Send + Sync {
async fn remove_file(&self, path: &Path, options: RemoveOptions) -> Result<()>;
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>>;
async fn load(&self, path: &Path) -> Result<String>;
async fn atomic_write(&self, path: PathBuf, text: String) -> Result<()>;
async fn save(&self, path: &Path, text: &Rope, line_ending: LineEnding) -> Result<()>;
async fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
async fn is_file(&self, path: &Path) -> bool;
@ -260,6 +263,18 @@ impl Fs for RealFs {
Ok(text)
}
async fn atomic_write(&self, path: PathBuf, data: String) -> Result<()> {
smol::unblock(move || {
let mut tmp_file = NamedTempFile::new()?;
tmp_file.write_all(data.as_bytes())?;
tmp_file.persist(path)?;
Ok::<(), anyhow::Error>(())
})
.await?;
Ok(())
}
async fn save(&self, path: &Path, text: &Rope, line_ending: LineEnding) -> Result<()> {
let buffer_size = text.summary().len.min(10 * 1024);
let file = smol::fs::File::create(path).await?;
@ -880,6 +895,14 @@ impl Fs for FakeFs {
entry.file_content(&path).cloned()
}
async fn atomic_write(&self, path: PathBuf, data: String) -> Result<()> {
self.simulate_random_delay().await;
let path = normalize_path(path.as_path());
self.insert_file(path, data.to_string()).await;
Ok(())
}
async fn save(&self, path: &Path, text: &Rope, line_ending: LineEnding) -> Result<()> {
self.simulate_random_delay().await;
let path = normalize_path(path);