Add rs-notify implementation of fs::watch (#9040)

This PR simplifies the Zed file system abstraction and implements
`Fs::watch` for linux and windows.

TODO:
- [x] Figure out why this fails to initialize the file watchers when we
have to initialize the config directory paths, but succeeds on
subsequent runs.
- [x] Fix macOS dependencies on old fsevents::Event crate

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-03-08 22:18:44 -08:00 committed by GitHub
parent 456efb53ad
commit ca696fd5f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 478 additions and 493 deletions

View file

@ -48,7 +48,6 @@ extensions_ui.workspace = true
feedback.workspace = true
file_finder.workspace = true
fs.workspace = true
fsevent.workspace = true
futures.workspace = true
go_to_line.workspace = true
gpui.workspace = true

View file

@ -11,8 +11,6 @@ use db::kvp::KEY_VALUE_STORE;
use editor::Editor;
use env_logger::Builder;
use fs::RealFs;
#[cfg(target_os = "macos")]
use fsevent::StreamFlags;
use futures::{future, StreamExt};
use gpui::{App, AppContext, AsyncAppContext, Context, SemanticVersion, Task};
use isahc::{prelude::Configurable, Request};
@ -184,7 +182,6 @@ fn main() {
);
load_user_themes_in_background(fs.clone(), cx);
#[cfg(target_os = "macos")]
watch_themes(fs.clone(), cx);
cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
@ -465,10 +462,11 @@ async fn restore_or_create_workspace(app_state: Arc<AppState>, cx: AsyncAppConte
fn init_paths() {
std::fs::create_dir_all(&*util::paths::CONFIG_DIR).expect("could not create config path");
std::fs::create_dir_all(&*util::paths::EXTENSIONS_DIR)
.expect("could not create extensions path");
std::fs::create_dir_all(&*util::paths::LANGUAGES_DIR).expect("could not create languages path");
std::fs::create_dir_all(&*util::paths::DB_DIR).expect("could not create database path");
std::fs::create_dir_all(&*util::paths::LOGS_DIR).expect("could not create logs path");
#[cfg(target_os = "linux")]
std::fs::create_dir_all(&*util::paths::TEMP_DIR).expect("could not create tmp path");
}
@ -974,9 +972,7 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
.detach_and_log_err(cx);
}
// todo(linux): Port fsevents to linux
/// Spawns a background task to watch the themes directory for changes.
#[cfg(target_os = "macos")]
fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
use std::time::Duration;
cx.spawn(|cx| async move {
@ -984,17 +980,14 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
.watch(&paths::THEMES_DIR.clone(), Duration::from_millis(100))
.await;
while let Some(events) = events.next().await {
for event in events {
if event.flags.contains(StreamFlags::ITEM_REMOVED) {
// Theme was removed, don't need to reload.
// We may want to remove the theme from the registry, in this case.
} else {
while let Some(paths) = events.next().await {
for path in paths {
if fs.metadata(&path).await.ok().flatten().is_some() {
if let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
{
if let Some(()) = theme_registry
.load_user_theme(&event.path, fs.clone())
.load_user_theme(&path, fs.clone())
.await
.log_err()
{