Fix crash when launching Zed.exe directly from target/debug dir (#9112)

As I described in #9111 , the PR fixs this crash.


Release Notes:

- N/A
This commit is contained in:
张小白 2024-03-14 03:08:00 +08:00 committed by GitHub
parent a56a260778
commit 2abb5aeaf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -184,8 +184,6 @@ fn main() {
load_user_themes_in_background(fs.clone(), cx);
watch_themes(fs.clone(), cx);
cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
.detach();
watch_file_types(fs.clone(), cx);
languages.set_theme(cx.theme().clone());
@ -1004,32 +1002,20 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
.detach()
}
#[cfg(debug_assertions)]
async fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>) {
use std::time::Duration;
let reload_debounce = Duration::from_millis(250);
let mut events = fs
.watch("crates/zed/src/languages".as_ref(), reload_debounce)
.await;
while (events.next().await).is_some() {
languages.reload();
}
}
#[cfg(debug_assertions)]
fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
use std::time::Duration;
let path = {
let p = Path::new("assets/icons/file_icons/file_types.json");
let Ok(full_path) = p.canonicalize() else {
return;
};
full_path
};
cx.spawn(|cx| async move {
let mut events = fs
.watch(
"assets/icons/file_icons/file_types.json".as_ref(),
Duration::from_millis(100),
)
.await;
let mut events = fs.watch(path.as_path(), Duration::from_millis(100)).await;
while (events.next().await).is_some() {
cx.update(|cx| {
cx.update_global(|file_types, _| {
@ -1044,6 +1030,3 @@ fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
#[cfg(not(debug_assertions))]
fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut AppContext) {}
#[cfg(not(debug_assertions))]
async fn watch_languages(_fs: Arc<dyn fs::Fs>, _languages: Arc<LanguageRegistry>) {}