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