This commit is contained in:
Antonio Scandurra
2021-07-09 18:32:57 +02:00
parent 0e19b061d4
commit 13c56cf6ce
2 changed files with 31 additions and 33 deletions
+7 -16
View File
@@ -204,22 +204,13 @@ impl Background {
_phantom: PhantomData,
};
(scheduler)(&mut scope);
match self {
Self::Deterministic(_) => {
for spawned in scope.futures {
spawned.await;
}
}
Self::Production { executor, .. } => {
let spawned = scope
.futures
.into_iter()
.map(|f| executor.spawn(f))
.collect::<Vec<_>>();
for task in spawned {
task.await;
}
}
let spawned = scope
.futures
.into_iter()
.map(|f| self.spawn(f))
.collect::<Vec<_>>();
for task in spawned {
task.await;
}
}
}
+24 -17
View File
@@ -66,7 +66,7 @@ pub fn init(cx: &mut MutableAppContext, rpc: rpc::Client) {
}
#[async_trait::async_trait]
trait Fs: Send + Sync {
pub trait Fs: Send + Sync {
async fn entry(
&self,
root_char_bag: CharBag,
@@ -83,12 +83,13 @@ trait Fs: Send + Sync {
) -> Result<Pin<Box<dyn 'a + Stream<Item = Result<Entry>> + Send>>>;
async fn load(&self, path: &Path) -> Result<String>;
async fn save(&self, path: &Path, text: &Rope) -> Result<()>;
async fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
}
struct OsFs;
struct ProductionFs;
#[async_trait::async_trait]
impl Fs for OsFs {
impl Fs for ProductionFs {
async fn entry(
&self,
root_char_bag: CharBag,
@@ -183,6 +184,10 @@ impl Fs for OsFs {
writer.flush().await?;
Ok(())
}
async fn canonicalize(&self, path: &Path) -> Result<PathBuf> {
Ok(smol::fs::canonicalize(path).await?)
}
}
#[derive(Clone)]
@@ -403,20 +408,22 @@ impl Fs for InMemoryFs {
} else {
let inode = state.next_inode;
state.next_inode += 1;
state.entries.insert(
path.to_path_buf(),
InMemoryEntry {
inode,
mtime: SystemTime::now(),
is_dir: false,
is_symlink: false,
content: Some(text.chunks().collect()),
},
);
let entry = InMemoryEntry {
inode,
mtime: SystemTime::now(),
is_dir: false,
is_symlink: false,
content: Some(text.chunks().collect()),
};
state.entries.insert(path.to_path_buf(), entry);
state.emit_event(path).await;
Ok(())
}
}
async fn canonicalize(&self, path: &Path) -> Result<PathBuf> {
Ok(path.to_path_buf())
}
}
#[derive(Clone, Debug)]
@@ -462,7 +469,7 @@ impl Worktree {
languages: Arc<LanguageRegistry>,
cx: &mut ModelContext<Worktree>,
) -> Self {
let fs = Arc::new(OsFs);
let fs = Arc::new(ProductionFs);
let (mut tree, scan_states_tx) = LocalWorktree::new(path, languages, fs.clone(), cx);
let (event_stream, event_stream_handle) = fsevent::EventStream::new(
&[tree.snapshot.abs_path.as_ref()],
@@ -2169,7 +2176,7 @@ impl BackgroundScanner {
break;
}
if self.process_events(events).await {
if !self.process_events(events).await {
break;
}
@@ -2339,7 +2346,7 @@ impl BackgroundScanner {
let mut snapshot = self.snapshot();
snapshot.scan_id += 1;
let root_abs_path = if let Ok(abs_path) = snapshot.abs_path.canonicalize() {
let root_abs_path = if let Ok(abs_path) = self.fs.canonicalize(&snapshot.abs_path).await {
abs_path
} else {
return false;
@@ -3258,7 +3265,7 @@ mod tests {
next_entry_id: Default::default(),
})),
notify_tx,
Arc::new(OsFs),
Arc::new(ProductionFs),
Arc::new(gpui::executor::Background::new()),
);
smol::block_on(scanner.scan_dirs()).unwrap();