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