main.rs

  1#![allow(unused_variables, dead_code, unused_mut)]
  2// todo!() this is to make transition easier.
  3
  4// Allow binary to be called Zed for a nice application menu when running executable directly
  5#![allow(non_snake_case)]
  6
  7use anyhow::{anyhow, Context as _, Result};
  8use backtrace::Backtrace;
  9use chrono::Utc;
 10use cli::FORCE_CLI_MODE_ENV_VAR_NAME;
 11use client::{Client, UserStore};
 12use db::kvp::KEY_VALUE_STORE;
 13use editor::Editor;
 14use fs::RealFs;
 15use futures::StreamExt;
 16use gpui::{App, AppContext, AsyncAppContext, Context, SemanticVersion, Task};
 17use isahc::{prelude::Configurable, Request};
 18use language::LanguageRegistry;
 19use log::LevelFilter;
 20
 21use node_runtime::RealNodeRuntime;
 22use parking_lot::Mutex;
 23use serde::{Deserialize, Serialize};
 24use settings::{
 25    default_settings, handle_keymap_file_changes, handle_settings_file_changes, watch_config_file,
 26    Settings, SettingsStore,
 27};
 28use simplelog::ConfigBuilder;
 29use smol::process::Command;
 30use std::{
 31    env,
 32    ffi::OsStr,
 33    fs::OpenOptions,
 34    io::{IsTerminal, Write},
 35    panic,
 36    path::{Path, PathBuf},
 37    sync::{
 38        atomic::{AtomicU32, Ordering},
 39        Arc, Weak,
 40    },
 41    thread,
 42};
 43use theme::ActiveTheme;
 44use util::{
 45    async_maybe,
 46    channel::{parse_zed_link, AppCommitSha, ReleaseChannel, RELEASE_CHANNEL},
 47    http::{self, HttpClient},
 48    paths, ResultExt,
 49};
 50use uuid::Uuid;
 51use welcome::{show_welcome_experience, FIRST_OPEN};
 52use workspace::{AppState, WorkspaceStore};
 53use zed2::{
 54    build_window_options, ensure_only_instance, handle_cli_connection, initialize_workspace,
 55    languages, Assets, IsOnlyInstance, OpenListener, OpenRequest,
 56};
 57
 58mod open_listener;
 59
 60fn main() {
 61    menu::init();
 62    zed_actions::init();
 63
 64    let http = http::client();
 65    init_paths();
 66    init_logger();
 67
 68    if ensure_only_instance() != IsOnlyInstance::Yes {
 69        return;
 70    }
 71
 72    log::info!("========== starting zed ==========");
 73    let app = App::production(Arc::new(Assets));
 74
 75    let (installation_id, existing_installation_id_found) = app
 76        .background_executor()
 77        .block(installation_id())
 78        .ok()
 79        .unzip();
 80    let session_id = Uuid::new_v4().to_string();
 81    init_panic_hook(&app, installation_id.clone(), session_id.clone());
 82
 83    let fs = Arc::new(RealFs);
 84    let user_settings_file_rx = watch_config_file(
 85        &app.background_executor(),
 86        fs.clone(),
 87        paths::SETTINGS.clone(),
 88    );
 89    let user_keymap_file_rx = watch_config_file(
 90        &app.background_executor(),
 91        fs.clone(),
 92        paths::KEYMAP.clone(),
 93    );
 94
 95    let login_shell_env_loaded = if stdout_is_a_pty() {
 96        Task::ready(())
 97    } else {
 98        app.background_executor().spawn(async {
 99            load_login_shell_environment().await.log_err();
100        })
101    };
102
103    let (listener, mut open_rx) = OpenListener::new();
104    let listener = Arc::new(listener);
105    let open_listener = listener.clone();
106    app.on_open_urls(move |urls, _| open_listener.open_urls(&urls));
107    app.on_reopen(move |cx| {
108        if cx.has_global::<Weak<AppState>>() {
109            if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
110                workspace::open_new(&app_state, cx, |workspace, cx| {
111                    Editor::new_file(workspace, &Default::default(), cx)
112                })
113                .detach();
114            }
115        }
116    });
117
118    app.run(move |cx| {
119        cx.set_global(*RELEASE_CHANNEL);
120        if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {
121            cx.set_global(AppCommitSha(build_sha.into()))
122        }
123
124        cx.set_global(listener.clone());
125
126        load_embedded_fonts(cx);
127
128        let mut store = SettingsStore::default();
129        store
130            .set_default_settings(default_settings().as_ref(), cx)
131            .unwrap();
132        cx.set_global(store);
133        handle_settings_file_changes(user_settings_file_rx, cx);
134        handle_keymap_file_changes(user_keymap_file_rx, cx);
135
136        let client = client::Client::new(http.clone(), cx);
137        let mut languages = LanguageRegistry::new(login_shell_env_loaded);
138        let copilot_language_server_id = languages.next_language_server_id();
139        languages.set_executor(cx.background_executor().clone());
140        languages.set_language_server_download_dir(paths::LANGUAGES_DIR.clone());
141        let languages = Arc::new(languages);
142        let node_runtime = RealNodeRuntime::new(http.clone());
143
144        language::init(cx);
145        languages::init(languages.clone(), node_runtime.clone(), cx);
146        let user_store = cx.build_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
147        let workspace_store = cx.build_model(|cx| WorkspaceStore::new(client.clone(), cx));
148
149        cx.set_global(client.clone());
150
151        theme::init(theme::LoadThemes::All, cx);
152        project::Project::init(&client, cx);
153        client::init(&client, cx);
154        command_palette::init(cx);
155        language::init(cx);
156        editor::init(cx);
157        diagnostics::init(cx);
158        copilot::init(
159            copilot_language_server_id,
160            http.clone(),
161            node_runtime.clone(),
162            cx,
163        );
164        // assistant::init(cx);
165        // component_test::init(cx);
166
167        // cx.spawn(|_| watch_languages(fs.clone(), languages.clone()))
168        //     .detach();
169        watch_file_types(fs.clone(), cx);
170
171        languages.set_theme(cx.theme().clone());
172        cx.observe_global::<SettingsStore>({
173            let languages = languages.clone();
174            move |cx| languages.set_theme(cx.theme().clone())
175        })
176        .detach();
177
178        client.telemetry().start(installation_id, session_id, cx);
179        let telemetry_settings = *client::TelemetrySettings::get_global(cx);
180        let event_operation = match existing_installation_id_found {
181            Some(false) => "first open",
182            _ => "open",
183        };
184        client
185            .telemetry()
186            .report_app_event(telemetry_settings, event_operation);
187
188        let app_state = Arc::new(AppState {
189            languages,
190            client: client.clone(),
191            user_store: user_store.clone(),
192            fs,
193            build_window_options,
194            call_factory: call::Call::new,
195            workspace_store,
196            node_runtime,
197        });
198        cx.set_global(Arc::downgrade(&app_state));
199
200        audio::init(Assets, cx);
201        auto_update::init(http.clone(), client::ZED_SERVER_URL.clone(), cx);
202
203        workspace::init(app_state.clone(), cx);
204        // recent_projects::init(cx);
205
206        go_to_line::init(cx);
207        file_finder::init(cx);
208        // outline::init(cx);
209        // project_symbols::init(cx);
210        project_panel::init(Assets, cx);
211        channel::init(&client, user_store.clone(), cx);
212        // diagnostics::init(cx);
213        search::init(cx);
214        // semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
215        // vim::init(cx);
216        terminal_view::init(cx);
217
218        // journal2::init(app_state.clone(), cx);
219        // language_selector::init(cx);
220        theme_selector::init(cx);
221        // activity_indicator::init(cx);
222        // language_tools::init(cx);
223        call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
224        collab_ui::init(&app_state, cx);
225        // feedback::init(cx);
226        welcome::init(cx);
227
228        // cx.set_menus(menus::menus());
229        initialize_workspace(app_state.clone(), cx);
230
231        if stdout_is_a_pty() {
232            cx.activate(true);
233            let urls = collect_url_args();
234            if !urls.is_empty() {
235                listener.open_urls(&urls)
236            }
237        } else {
238            upload_previous_panics(http.clone(), cx);
239
240            // TODO Development mode that forces the CLI mode usually runs Zed binary as is instead
241            // of an *app, hence gets no specific callbacks run. Emulate them here, if needed.
242            if std::env::var(FORCE_CLI_MODE_ENV_VAR_NAME).ok().is_some()
243                && !listener.triggered.load(Ordering::Acquire)
244            {
245                listener.open_urls(&collect_url_args())
246            }
247        }
248
249        let mut triggered_authentication = false;
250
251        fn open_paths_and_log_errs(
252            paths: &[PathBuf],
253            app_state: &Arc<AppState>,
254            cx: &mut AppContext,
255        ) {
256            let task = workspace::open_paths(&paths, &app_state, None, cx);
257            cx.spawn(|cx| async move {
258                if let Some((_window, results)) = task.await.log_err() {
259                    for result in results {
260                        if let Some(Err(e)) = result {
261                            log::error!("Error opening path: {}", e);
262                        }
263                    }
264                }
265            })
266            .detach();
267        }
268
269        match open_rx.try_next() {
270            Ok(Some(OpenRequest::Paths { paths })) => {
271                open_paths_and_log_errs(&paths, &app_state, cx)
272            }
273            Ok(Some(OpenRequest::CliConnection { connection })) => {
274                let app_state = app_state.clone();
275                cx.spawn(move |cx| handle_cli_connection(connection, app_state, cx))
276                    .detach();
277            }
278            Ok(Some(OpenRequest::JoinChannel { channel_id: _ })) => {
279                triggered_authentication = true;
280                let app_state = app_state.clone();
281                let client = client.clone();
282                cx.spawn(|mut cx| async move {
283                    // ignore errors here, we'll show a generic "not signed in"
284                    let _ = authenticate(client, &cx).await;
285                    //todo!()
286                    // cx.update(|cx| workspace::join_channel(channel_id, app_state, None, cx))
287                    // .await
288                    anyhow::Ok(())
289                })
290                .detach_and_log_err(cx)
291            }
292            Ok(Some(OpenRequest::OpenChannelNotes { channel_id: _ })) => {
293                todo!()
294            }
295            Ok(None) | Err(_) => cx
296                .spawn({
297                    let app_state = app_state.clone();
298                    |cx| async move { restore_or_create_workspace(&app_state, cx).await }
299                })
300                .detach(),
301        }
302
303        let app_state = app_state.clone();
304        cx.spawn(|cx| async move {
305            while let Some(request) = open_rx.next().await {
306                match request {
307                    OpenRequest::Paths { paths } => {
308                        cx.update(|cx| open_paths_and_log_errs(&paths, &app_state, cx))
309                            .ok();
310                    }
311                    OpenRequest::CliConnection { connection } => {
312                        let app_state = app_state.clone();
313                        cx.spawn(move |cx| {
314                            handle_cli_connection(connection, app_state.clone(), cx)
315                        })
316                        .detach();
317                    }
318                    OpenRequest::JoinChannel { channel_id: _ } => {
319                        todo!()
320                    }
321                    OpenRequest::OpenChannelNotes { channel_id: _ } => {
322                        todo!()
323                    }
324                }
325            }
326        })
327        .detach();
328
329        if !triggered_authentication {
330            cx.spawn(|cx| async move { authenticate(client, &cx).await })
331                .detach_and_log_err(cx);
332        }
333    });
334}
335
336async fn authenticate(client: Arc<Client>, cx: &AsyncAppContext) -> Result<()> {
337    if stdout_is_a_pty() {
338        if client::IMPERSONATE_LOGIN.is_some() {
339            client.authenticate_and_connect(false, &cx).await?;
340        }
341    } else if client.has_keychain_credentials(&cx) {
342        client.authenticate_and_connect(true, &cx).await?;
343    }
344    Ok::<_, anyhow::Error>(())
345}
346
347async fn installation_id() -> Result<(String, bool)> {
348    let legacy_key_name = "device_id";
349
350    if let Ok(Some(installation_id)) = KEY_VALUE_STORE.read_kvp(legacy_key_name) {
351        Ok((installation_id, true))
352    } else {
353        let installation_id = Uuid::new_v4().to_string();
354
355        KEY_VALUE_STORE
356            .write_kvp(legacy_key_name.to_string(), installation_id.clone())
357            .await?;
358
359        Ok((installation_id, false))
360    }
361}
362
363async fn restore_or_create_workspace(app_state: &Arc<AppState>, mut cx: AsyncAppContext) {
364    async_maybe!({
365        if let Some(location) = workspace::last_opened_workspace_paths().await {
366            cx.update(|cx| workspace::open_paths(location.paths().as_ref(), app_state, None, cx))?
367                .await
368                .log_err();
369        } else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) {
370            cx.update(|cx| show_welcome_experience(app_state, cx))
371                .log_err();
372        } else {
373            cx.update(|cx| {
374                workspace::open_new(app_state, cx, |workspace, cx| {
375                    Editor::new_file(workspace, &Default::default(), cx)
376                })
377                .detach();
378            })?;
379        }
380        anyhow::Ok(())
381    })
382    .await
383    .log_err();
384}
385
386fn init_paths() {
387    std::fs::create_dir_all(&*util::paths::CONFIG_DIR).expect("could not create config path");
388    std::fs::create_dir_all(&*util::paths::LANGUAGES_DIR).expect("could not create languages path");
389    std::fs::create_dir_all(&*util::paths::DB_DIR).expect("could not create database path");
390    std::fs::create_dir_all(&*util::paths::LOGS_DIR).expect("could not create logs path");
391}
392
393fn init_logger() {
394    if stdout_is_a_pty() {
395        env_logger::init();
396    } else {
397        let level = LevelFilter::Info;
398
399        // Prevent log file from becoming too large.
400        const KIB: u64 = 1024;
401        const MIB: u64 = 1024 * KIB;
402        const MAX_LOG_BYTES: u64 = MIB;
403        if std::fs::metadata(&*paths::LOG).map_or(false, |metadata| metadata.len() > MAX_LOG_BYTES)
404        {
405            let _ = std::fs::rename(&*paths::LOG, &*paths::OLD_LOG);
406        }
407
408        let log_file = OpenOptions::new()
409            .create(true)
410            .append(true)
411            .open(&*paths::LOG)
412            .expect("could not open logfile");
413
414        let config = ConfigBuilder::new()
415            .set_time_format_str("%Y-%m-%dT%T") //All timestamps are UTC
416            .build();
417
418        simplelog::WriteLogger::init(level, config, log_file).expect("could not initialize logger");
419    }
420}
421
422#[derive(Serialize, Deserialize)]
423struct LocationData {
424    file: String,
425    line: u32,
426}
427
428#[derive(Serialize, Deserialize)]
429struct Panic {
430    thread: String,
431    payload: String,
432    #[serde(skip_serializing_if = "Option::is_none")]
433    location_data: Option<LocationData>,
434    backtrace: Vec<String>,
435    app_version: String,
436    release_channel: String,
437    os_name: String,
438    os_version: Option<String>,
439    architecture: String,
440    panicked_on: i64,
441    #[serde(skip_serializing_if = "Option::is_none")]
442    installation_id: Option<String>,
443    session_id: String,
444}
445
446#[derive(Serialize)]
447struct PanicRequest {
448    panic: Panic,
449    token: String,
450}
451
452static PANIC_COUNT: AtomicU32 = AtomicU32::new(0);
453
454fn init_panic_hook(app: &App, installation_id: Option<String>, session_id: String) {
455    let is_pty = stdout_is_a_pty();
456    let app_metadata = app.metadata();
457
458    panic::set_hook(Box::new(move |info| {
459        let prior_panic_count = PANIC_COUNT.fetch_add(1, Ordering::SeqCst);
460        if prior_panic_count > 0 {
461            // Give the panic-ing thread time to write the panic file
462            loop {
463                std::thread::yield_now();
464            }
465        }
466
467        let thread = thread::current();
468        let thread_name = thread.name().unwrap_or("<unnamed>");
469
470        let payload = info
471            .payload()
472            .downcast_ref::<&str>()
473            .map(|s| s.to_string())
474            .or_else(|| info.payload().downcast_ref::<String>().map(|s| s.clone()))
475            .unwrap_or_else(|| "Box<Any>".to_string());
476
477        if *util::channel::RELEASE_CHANNEL == ReleaseChannel::Dev {
478            let location = info.location().unwrap();
479            let backtrace = Backtrace::new();
480            eprintln!(
481                "Thread {:?} panicked with {:?} at {}:{}:{}\n{:?}",
482                thread_name,
483                payload,
484                location.file(),
485                location.line(),
486                location.column(),
487                backtrace,
488            );
489            std::process::exit(-1);
490        }
491
492        let app_version = client::ZED_APP_VERSION
493            .or(app_metadata.app_version)
494            .map_or("dev".to_string(), |v| v.to_string());
495
496        let backtrace = Backtrace::new();
497        let mut backtrace = backtrace
498            .frames()
499            .iter()
500            .filter_map(|frame| Some(format!("{:#}", frame.symbols().first()?.name()?)))
501            .collect::<Vec<_>>();
502
503        // Strip out leading stack frames for rust panic-handling.
504        if let Some(ix) = backtrace
505            .iter()
506            .position(|name| name == "rust_begin_unwind")
507        {
508            backtrace.drain(0..=ix);
509        }
510
511        let panic_data = Panic {
512            thread: thread_name.into(),
513            payload: payload.into(),
514            location_data: info.location().map(|location| LocationData {
515                file: location.file().into(),
516                line: location.line(),
517            }),
518            app_version: app_version.clone(),
519            release_channel: RELEASE_CHANNEL.display_name().into(),
520            os_name: app_metadata.os_name.into(),
521            os_version: app_metadata
522                .os_version
523                .as_ref()
524                .map(SemanticVersion::to_string),
525            architecture: env::consts::ARCH.into(),
526            panicked_on: Utc::now().timestamp_millis(),
527            backtrace,
528            installation_id: installation_id.clone(),
529            session_id: session_id.clone(),
530        };
531
532        if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {
533            log::error!("{}", panic_data_json);
534        }
535
536        if !is_pty {
537            if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() {
538                let timestamp = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string();
539                let panic_file_path = paths::LOGS_DIR.join(format!("zed-{}.panic", timestamp));
540                let panic_file = std::fs::OpenOptions::new()
541                    .append(true)
542                    .create(true)
543                    .open(&panic_file_path)
544                    .log_err();
545                if let Some(mut panic_file) = panic_file {
546                    writeln!(&mut panic_file, "{}", panic_data_json).log_err();
547                    panic_file.flush().log_err();
548                }
549            }
550        }
551
552        std::process::abort();
553    }));
554}
555
556fn upload_previous_panics(http: Arc<dyn HttpClient>, cx: &mut AppContext) {
557    let telemetry_settings = *client::TelemetrySettings::get_global(cx);
558
559    cx.background_executor()
560        .spawn(async move {
561            let panic_report_url = format!("{}/api/panic", &*client::ZED_SERVER_URL);
562            let mut children = smol::fs::read_dir(&*paths::LOGS_DIR).await?;
563            while let Some(child) = children.next().await {
564                let child = child?;
565                let child_path = child.path();
566
567                if child_path.extension() != Some(OsStr::new("panic")) {
568                    continue;
569                }
570                let filename = if let Some(filename) = child_path.file_name() {
571                    filename.to_string_lossy()
572                } else {
573                    continue;
574                };
575
576                if !filename.starts_with("zed") {
577                    continue;
578                }
579
580                if telemetry_settings.diagnostics {
581                    let panic_file_content = smol::fs::read_to_string(&child_path)
582                        .await
583                        .context("error reading panic file")?;
584
585                    let panic = serde_json::from_str(&panic_file_content)
586                        .ok()
587                        .or_else(|| {
588                            panic_file_content
589                                .lines()
590                                .next()
591                                .and_then(|line| serde_json::from_str(line).ok())
592                        })
593                        .unwrap_or_else(|| {
594                            log::error!(
595                                "failed to deserialize panic file {:?}",
596                                panic_file_content
597                            );
598                            None
599                        });
600
601                    if let Some(panic) = panic {
602                        let body = serde_json::to_string(&PanicRequest {
603                            panic,
604                            token: client::ZED_SECRET_CLIENT_TOKEN.into(),
605                        })
606                        .unwrap();
607
608                        let request = Request::post(&panic_report_url)
609                            .redirect_policy(isahc::config::RedirectPolicy::Follow)
610                            .header("Content-Type", "application/json")
611                            .body(body.into())?;
612                        let response = http.send(request).await.context("error sending panic")?;
613                        if !response.status().is_success() {
614                            log::error!("Error uploading panic to server: {}", response.status());
615                        }
616                    }
617                }
618
619                // We've done what we can, delete the file
620                std::fs::remove_file(child_path)
621                    .context("error removing panic")
622                    .log_err();
623            }
624            Ok::<_, anyhow::Error>(())
625        })
626        .detach_and_log_err(cx);
627}
628
629async fn load_login_shell_environment() -> Result<()> {
630    let marker = "ZED_LOGIN_SHELL_START";
631    let shell = env::var("SHELL").context(
632        "SHELL environment variable is not assigned so we can't source login environment variables",
633    )?;
634    let output = Command::new(&shell)
635        .args(["-lic", &format!("echo {marker} && /usr/bin/env -0")])
636        .output()
637        .await
638        .context("failed to spawn login shell to source login environment variables")?;
639    if !output.status.success() {
640        Err(anyhow!("login shell exited with error"))?;
641    }
642
643    let stdout = String::from_utf8_lossy(&output.stdout);
644
645    if let Some(env_output_start) = stdout.find(marker) {
646        let env_output = &stdout[env_output_start + marker.len()..];
647        for line in env_output.split_terminator('\0') {
648            if let Some(separator_index) = line.find('=') {
649                let key = &line[..separator_index];
650                let value = &line[separator_index + 1..];
651                env::set_var(key, value);
652            }
653        }
654        log::info!(
655            "set environment variables from shell:{}, path:{}",
656            shell,
657            env::var("PATH").unwrap_or_default(),
658        );
659    }
660
661    Ok(())
662}
663
664fn stdout_is_a_pty() -> bool {
665    std::env::var(FORCE_CLI_MODE_ENV_VAR_NAME).ok().is_none() && std::io::stdout().is_terminal()
666}
667
668fn collect_url_args() -> Vec<String> {
669    env::args()
670        .skip(1)
671        .filter_map(|arg| match std::fs::canonicalize(Path::new(&arg)) {
672            Ok(path) => Some(format!("file://{}", path.to_string_lossy())),
673            Err(error) => {
674                if let Some(_) = parse_zed_link(&arg) {
675                    Some(arg)
676                } else {
677                    log::error!("error parsing path argument: {}", error);
678                    None
679                }
680            }
681        })
682        .collect()
683}
684
685fn load_embedded_fonts(cx: &AppContext) {
686    let asset_source = cx.asset_source();
687    let font_paths = asset_source.list("fonts").unwrap();
688    let embedded_fonts = Mutex::new(Vec::new());
689    let executor = cx.background_executor();
690
691    executor.block(executor.scoped(|scope| {
692        for font_path in &font_paths {
693            if !font_path.ends_with(".ttf") {
694                continue;
695            }
696
697            scope.spawn(async {
698                let font_bytes = asset_source.load(font_path).unwrap().to_vec();
699                embedded_fonts.lock().push(Arc::from(font_bytes));
700            });
701        }
702    }));
703
704    cx.text_system()
705        .add_fonts(&embedded_fonts.into_inner())
706        .unwrap();
707}
708
709#[cfg(debug_assertions)]
710async fn watch_languages(fs: Arc<dyn fs::Fs>, languages: Arc<LanguageRegistry>) -> Option<()> {
711    use std::time::Duration;
712
713    let mut events = fs
714        .watch(
715            "crates/zed2/src/languages".as_ref(),
716            Duration::from_millis(100),
717        )
718        .await;
719    while (events.next().await).is_some() {
720        languages.reload();
721    }
722    Some(())
723}
724
725#[cfg(debug_assertions)]
726fn watch_file_types(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
727    use std::time::Duration;
728
729    cx.spawn(|mut cx| async move {
730        let mut events = fs
731            .watch(
732                "assets/icons/file_icons/file_types.json".as_ref(),
733                Duration::from_millis(100),
734            )
735            .await;
736        while (events.next().await).is_some() {
737            cx.update(|cx| {
738                cx.update_global(|file_types, _| {
739                    *file_types = project_panel::file_associations::FileAssociations::new(Assets);
740                });
741            })
742            .ok();
743        }
744    })
745    .detach()
746}
747
748#[cfg(not(debug_assertions))]
749async fn watch_languages(_: Arc<dyn fs::Fs>, _: Arc<LanguageRegistry>) -> Option<()> {
750    None
751}
752
753#[cfg(not(debug_assertions))]
754fn watch_file_types(_fs: Arc<dyn fs::Fs>, _cx: &mut AppContext) {}