zed2.rs

  1#![allow(unused_variables, unused_mut)]
  2//todo!()
  3
  4mod assets;
  5pub mod languages;
  6mod only_instance;
  7mod open_listener;
  8
  9pub use assets::*;
 10use collections::VecDeque;
 11use editor::{Editor, MultiBuffer};
 12use gpui::{
 13    actions, point, px, AppContext, Context, FocusableView, PromptLevel, TitlebarOptions,
 14    ViewContext, VisualContext, WindowBounds, WindowKind, WindowOptions,
 15};
 16pub use only_instance::*;
 17pub use open_listener::*;
 18
 19use anyhow::{anyhow, Context as _};
 20use project_panel::ProjectPanel;
 21use settings::{initial_local_settings_content, Settings};
 22use std::{borrow::Cow, ops::Deref, sync::Arc};
 23use terminal_view::terminal_panel::TerminalPanel;
 24use util::{
 25    asset_str,
 26    channel::{AppCommitSha, ReleaseChannel},
 27    paths::{self, LOCAL_SETTINGS_RELATIVE_PATH},
 28    ResultExt,
 29};
 30use uuid::Uuid;
 31use workspace::{
 32    create_and_open_local_file, dock::PanelHandle,
 33    notifications::simple_message_notification::MessageNotification, open_new, AppState, NewFile,
 34    NewWindow, Workspace, WorkspaceSettings,
 35};
 36use zed_actions::{OpenBrowser, OpenZedURL};
 37
 38actions!(
 39    About,
 40    DebugElements,
 41    DecreaseBufferFontSize,
 42    Hide,
 43    HideOthers,
 44    IncreaseBufferFontSize,
 45    Minimize,
 46    OpenDefaultKeymap,
 47    OpenDefaultSettings,
 48    OpenKeymap,
 49    OpenLicenses,
 50    OpenLocalSettings,
 51    OpenLog,
 52    OpenSettings,
 53    OpenTelemetryLog,
 54    Quit,
 55    ResetBufferFontSize,
 56    ResetDatabase,
 57    ShowAll,
 58    ToggleFullScreen,
 59    Zoom,
 60);
 61
 62pub fn build_window_options(
 63    bounds: Option<WindowBounds>,
 64    display_uuid: Option<Uuid>,
 65    cx: &mut AppContext,
 66) -> WindowOptions {
 67    let bounds = bounds.unwrap_or(WindowBounds::Maximized);
 68    let display = display_uuid.and_then(|uuid| {
 69        cx.displays()
 70            .into_iter()
 71            .find(|display| display.uuid().ok() == Some(uuid))
 72    });
 73
 74    WindowOptions {
 75        bounds,
 76        titlebar: Some(TitlebarOptions {
 77            title: None,
 78            appears_transparent: true,
 79            traffic_light_position: Some(point(px(8.), px(8.))),
 80        }),
 81        center: false,
 82        focus: false,
 83        show: false,
 84        kind: WindowKind::Normal,
 85        is_movable: true,
 86        display_id: display.map(|display| display.id()),
 87    }
 88}
 89
 90pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
 91    cx.observe_new_views(move |workspace: &mut Workspace, cx| {
 92        let workspace_handle = cx.view().clone();
 93        cx.subscribe(&workspace_handle, {
 94            move |workspace, _, event, cx| {
 95                if let workspace::Event::PaneAdded(pane) = event {
 96                    pane.update(cx, |pane, cx| {
 97                        pane.toolbar().update(cx, |toolbar, cx| {
 98                            // todo!()
 99                            //     let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
100                            //     toolbar.add_item(breadcrumbs, cx);
101                            let buffer_search_bar = cx.build_view(search::BufferSearchBar::new);
102                            toolbar.add_item(buffer_search_bar.clone(), cx);
103                            //     let quick_action_bar = cx.add_view(|_| {
104                            //         QuickActionBar::new(buffer_search_bar, workspace)
105                            //     });
106                            //     toolbar.add_item(quick_action_bar, cx);
107                            let diagnostic_editor_controls =
108                                cx.build_view(|_| diagnostics::ToolbarControls::new());
109                            //     toolbar.add_item(diagnostic_editor_controls, cx);
110                            //     let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
111                            //     toolbar.add_item(project_search_bar, cx);
112                            //     let submit_feedback_button =
113                            //         cx.add_view(|_| SubmitFeedbackButton::new());
114                            //     toolbar.add_item(submit_feedback_button, cx);
115                            //     let feedback_info_text = cx.add_view(|_| FeedbackInfoText::new());
116                            //     toolbar.add_item(feedback_info_text, cx);
117                            //     let lsp_log_item =
118                            //         cx.add_view(|_| language_tools::LspLogToolbarItemView::new());
119                            //     toolbar.add_item(lsp_log_item, cx);
120                            //     let syntax_tree_item = cx
121                            //         .add_view(|_| language_tools::SyntaxTreeToolbarItemView::new());
122                            //     toolbar.add_item(syntax_tree_item, cx);
123                        })
124                    });
125                }
126            }
127        })
128        .detach();
129
130        //     cx.emit(workspace2::Event::PaneAdded(
131        //         workspace.active_pane().clone(),
132        //     ));
133
134        //     let collab_titlebar_item =
135        //         cx.add_view(|cx| CollabTitlebarItem::new(workspace, &workspace_handle, cx));
136        //     workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
137
138        //     let copilot =
139        //         cx.add_view(|cx| copilot_button::CopilotButton::new(app_state.fs.clone(), cx));
140        let diagnostic_summary =
141            cx.build_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx));
142        //     let activity_indicator = activity_indicator::ActivityIndicator::new(
143        //         workspace,
144        //         app_state.languages.clone(),
145        //         cx,
146        //     );
147        //     let active_buffer_language =
148        //         cx.add_view(|_| language_selector::ActiveBufferLanguage::new(workspace));
149        //     let vim_mode_indicator = cx.add_view(|cx| vim::ModeIndicator::new(cx));
150        //     let feedback_button = cx.add_view(|_| {
151        //         feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace)
152        //     });
153        //     let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new());
154        workspace.status_bar().update(cx, |status_bar, cx| {
155            status_bar.add_left_item(diagnostic_summary, cx);
156            // status_bar.add_left_item(activity_indicator, cx);
157
158            // status_bar.add_right_item(feedback_button, cx);
159            // status_bar.add_right_item(copilot, cx);
160            // status_bar.add_right_item(active_buffer_language, cx);
161            // status_bar.add_right_item(vim_mode_indicator, cx);
162            // status_bar.add_right_item(cursor_position, cx);
163        });
164
165        auto_update::notify_of_any_new_update(cx);
166
167        //     vim::observe_keystrokes(cx);
168
169        //     cx.on_window_should_close(|workspace, cx| {
170        //         if let Some(task) = workspace.close(&Default::default(), cx) {
171        //             task.detach_and_log_err(cx);
172        //         }
173        //         false
174        //     });
175
176        cx.spawn(|workspace_handle, mut cx| async move {
177            let project_panel = ProjectPanel::load(workspace_handle.clone(), cx.clone());
178            let terminal_panel = TerminalPanel::load(workspace_handle.clone(), cx.clone());
179            // let assistant_panel = AssistantPanel::load(workspace_handle.clone(), cx.clone());
180            let channels_panel =
181                collab_ui::collab_panel::CollabPanel::load(workspace_handle.clone(), cx.clone());
182            // let chat_panel =
183            //     collab_ui::chat_panel::ChatPanel::load(workspace_handle.clone(), cx.clone());
184            // let notification_panel = collab_ui::notification_panel::NotificationPanel::load(
185            //     workspace_handle.clone(),
186            //     cx.clone(),
187            // );
188            let (
189                project_panel,
190                terminal_panel,
191                //     assistant_panel,
192                channels_panel,
193                //     chat_panel,
194                //     notification_panel,
195            ) = futures::try_join!(
196                project_panel,
197                terminal_panel,
198                //     assistant_panel,
199                channels_panel,
200                //     chat_panel,
201                //     notification_panel,
202            )?;
203
204            workspace_handle.update(&mut cx, |workspace, cx| {
205                let project_panel_position = project_panel.position(cx);
206                workspace.add_panel(project_panel, cx);
207                workspace.add_panel(terminal_panel, cx);
208                //     workspace.add_panel(assistant_panel, cx);
209                workspace.add_panel(channels_panel, cx);
210                //     workspace.add_panel(chat_panel, cx);
211                //     workspace.add_panel(notification_panel, cx);
212
213                //     if !was_deserialized
214                //         && workspace
215                //             .project()
216                //             .read(cx)
217                //             .visible_worktrees(cx)
218                //             .any(|tree| {
219                //                 tree.read(cx)
220                //                     .root_entry()
221                //                     .map_or(false, |entry| entry.is_dir())
222                //             })
223                //     {
224                // workspace.toggle_dock(project_panel_position, cx);
225                //     }
226                // cx.focus_self();
227            })
228        })
229        .detach();
230
231        workspace
232            .register_action(about)
233            .register_action(|_, _: &Hide, cx| {
234                cx.hide();
235            })
236            .register_action(|_, _: &HideOthers, cx| {
237                cx.hide_other_apps();
238            })
239            .register_action(|_, _: &ShowAll, cx| {
240                cx.unhide_other_apps();
241            })
242            .register_action(|_, _: &Minimize, cx| {
243                cx.minimize_window();
244            })
245            .register_action(|_, _: &Zoom, cx| {
246                cx.zoom_window();
247            })
248            .register_action(|_, _: &ToggleFullScreen, cx| {
249                cx.toggle_full_screen();
250            })
251            .register_action(quit)
252            .register_action(|_, action: &OpenZedURL, cx| {
253                cx.global::<Arc<OpenListener>>()
254                    .open_urls(&[action.url.clone()])
255            })
256            .register_action(|_, action: &OpenBrowser, cx| cx.open_url(&action.url))
257            //todo!(buffer font size)
258            // cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {
259            //     theme::adjust_font_size(cx, |size| *size += 1.0)
260            // });
261            // cx.add_global_action(move |_: &DecreaseBufferFontSize, cx| {
262            //     theme::adjust_font_size(cx, |size| *size -= 1.0)
263            // });
264            // cx.add_global_action(move |_: &ResetBufferFontSize, cx| theme::reset_font_size(cx));
265            .register_action(|_, _: &install_cli::Install, cx| {
266                cx.spawn(|_, cx| async move {
267                    install_cli::install_cli(cx.deref())
268                        .await
269                        .context("error creating CLI symlink")
270                })
271                .detach_and_log_err(cx);
272            })
273            .register_action(|workspace, _: &OpenLog, cx| {
274                open_log_file(workspace, cx);
275            })
276            .register_action(|workspace, _: &OpenLicenses, cx| {
277                open_bundled_file(
278                    workspace,
279                    asset_str::<Assets>("licenses.md"),
280                    "Open Source License Attribution",
281                    "Markdown",
282                    cx,
283                );
284            })
285            .register_action(
286                move |workspace: &mut Workspace,
287                      _: &OpenTelemetryLog,
288                      cx: &mut ViewContext<Workspace>| {
289                    open_telemetry_log_file(workspace, cx);
290                },
291            )
292            .register_action(
293                move |_: &mut Workspace, _: &OpenKeymap, cx: &mut ViewContext<Workspace>| {
294                    create_and_open_local_file(&paths::KEYMAP, cx, Default::default)
295                        .detach_and_log_err(cx);
296                },
297            )
298            .register_action(
299                move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
300                    create_and_open_local_file(&paths::SETTINGS, cx, || {
301                        settings::initial_user_settings_content().as_ref().into()
302                    })
303                    .detach_and_log_err(cx);
304                },
305            )
306            .register_action(open_local_settings_file)
307            .register_action(
308                move |workspace: &mut Workspace,
309                      _: &OpenDefaultKeymap,
310                      cx: &mut ViewContext<Workspace>| {
311                    open_bundled_file(
312                        workspace,
313                        settings::default_keymap(),
314                        "Default Key Bindings",
315                        "JSON",
316                        cx,
317                    );
318                },
319            )
320            .register_action(
321                move |workspace: &mut Workspace,
322                      _: &OpenDefaultSettings,
323                      cx: &mut ViewContext<Workspace>| {
324                    open_bundled_file(
325                        workspace,
326                        settings::default_settings(),
327                        "Default Settings",
328                        "JSON",
329                        cx,
330                    );
331                },
332            )
333            //todo!()
334            // cx.add_action({
335            //     move |workspace: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| {
336            //         let app_state = workspace.app_state().clone();
337            //         let markdown = app_state.languages.language_for_name("JSON");
338            //         let window = cx.window();
339            //         cx.spawn(|workspace, mut cx| async move {
340            //             let markdown = markdown.await.log_err();
341            //             let content = to_string_pretty(&window.debug_elements(&cx).ok_or_else(|| {
342            //                 anyhow!("could not debug elements for window {}", window.id())
343            //             })?)
344            //             .unwrap();
345            //             workspace
346            //                 .update(&mut cx, |workspace, cx| {
347            //                     workspace.with_local_workspace(cx, move |workspace, cx| {
348            //                         let project = workspace.project().clone();
349            //                         let buffer = project
350            //                             .update(cx, |project, cx| {
351            //                                 project.create_buffer(&content, markdown, cx)
352            //                             })
353            //                             .expect("creating buffers on a local workspace always succeeds");
354            //                         let buffer = cx.add_model(|cx| {
355            //                             MultiBuffer::singleton(buffer, cx)
356            //                                 .with_title("Debug Elements".into())
357            //                         });
358            //                         workspace.add_item(
359            //                             Box::new(cx.add_view(|cx| {
360            //                                 Editor::for_multibuffer(buffer, Some(project.clone()), cx)
361            //                             })),
362            //                             cx,
363            //                         );
364            //                     })
365            //                 })?
366            //                 .await
367            //         })
368            //         .detach_and_log_err(cx);
369            //     }
370            // });
371            // .register_action(
372            //     |workspace: &mut Workspace,
373            //      _: &project_panel::ToggleFocus,
374            //      cx: &mut ViewContext<Workspace>| {
375            //         workspace.toggle_panel_focus::<ProjectPanel>(cx);
376            //     },
377            // );
378            // cx.add_action(
379            //     |workspace: &mut Workspace,
380            //      _: &collab_ui::collab_panel::ToggleFocus,
381            //      cx: &mut ViewContext<Workspace>| {
382            //         workspace.toggle_panel_focus::<collab_ui::collab_panel::CollabPanel>(cx);
383            //     },
384            // );
385            // cx.add_action(
386            //     |workspace: &mut Workspace,
387            //      _: &collab_ui::chat_panel::ToggleFocus,
388            //      cx: &mut ViewContext<Workspace>| {
389            //         workspace.toggle_panel_focus::<collab_ui::chat_panel::ChatPanel>(cx);
390            //     },
391            // );
392            // cx.add_action(
393            //     |workspace: &mut Workspace,
394            //      _: &collab_ui::notification_panel::ToggleFocus,
395            //      cx: &mut ViewContext<Workspace>| {
396            //         workspace.toggle_panel_focus::<collab_ui::notification_panel::NotificationPanel>(cx);
397            //     },
398            // );
399            // cx.add_action(
400            //     |workspace: &mut Workspace,
401            //      _: &terminal_panel::ToggleFocus,
402            //      cx: &mut ViewContext<Workspace>| {
403            //         workspace.toggle_panel_focus::<TerminalPanel>(cx);
404            //     },
405            // );
406            .register_action({
407                let app_state = Arc::downgrade(&app_state);
408                move |_, _: &NewWindow, cx| {
409                    if let Some(app_state) = app_state.upgrade() {
410                        open_new(&app_state, cx, |workspace, cx| {
411                            Editor::new_file(workspace, &Default::default(), cx)
412                        })
413                        .detach();
414                    }
415                }
416            })
417            .register_action({
418                let app_state = Arc::downgrade(&app_state);
419                move |_, _: &NewFile, cx| {
420                    if let Some(app_state) = app_state.upgrade() {
421                        open_new(&app_state, cx, |workspace, cx| {
422                            Editor::new_file(workspace, &Default::default(), cx)
423                        })
424                        .detach();
425                    }
426                }
427            });
428
429        workspace.focus_handle(cx).focus(cx);
430        //todo!()
431        // load_default_keymap(cx);
432    })
433    .detach();
434}
435
436fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {
437    use std::fmt::Write as _;
438
439    let app_name = cx.global::<ReleaseChannel>().display_name();
440    let version = env!("CARGO_PKG_VERSION");
441    let mut message = format!("{app_name} {version}");
442    if let Some(sha) = cx.try_global::<AppCommitSha>() {
443        write!(&mut message, "\n\n{}", sha.0).unwrap();
444    }
445
446    let prompt = cx.prompt(PromptLevel::Info, &message, &["OK"]);
447    cx.foreground_executor()
448        .spawn(async {
449            prompt.await.ok();
450        })
451        .detach();
452}
453
454fn quit(_: &mut Workspace, _: &Quit, cx: &mut gpui::ViewContext<Workspace>) {
455    let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;
456    cx.spawn(|_, mut cx| async move {
457        let mut workspace_windows = cx.update(|_, cx| {
458            cx.windows()
459                .into_iter()
460                .filter_map(|window| window.downcast::<Workspace>())
461                .collect::<Vec<_>>()
462        })?;
463
464        // If multiple windows have unsaved changes, and need a save prompt,
465        // prompt in the active window before switching to a different window.
466        cx.update(|_, cx| {
467            workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false));
468        })
469        .log_err();
470
471        if let (true, Some(window)) = (should_confirm, workspace_windows.first().copied()) {
472            let answer = cx
473                .update(|_, cx| {
474                    cx.prompt(
475                        PromptLevel::Info,
476                        "Are you sure you want to quit?",
477                        &["Quit", "Cancel"],
478                    )
479                })
480                .log_err();
481
482            if let Some(mut answer) = answer {
483                let answer = answer.await.ok();
484                if answer != Some(0) {
485                    return Ok(());
486                }
487            }
488        }
489
490        // If the user cancels any save prompt, then keep the app open.
491        for window in workspace_windows {
492            if let Some(should_close) = window
493                .update(&mut cx, |workspace, cx| {
494                    workspace.prepare_to_close(true, cx)
495                })
496                .log_err()
497            {
498                if !should_close.await? {
499                    return Ok(());
500                }
501            }
502        }
503        cx.update(|_, cx| {
504            cx.quit();
505        })?;
506        anyhow::Ok(())
507    })
508    .detach_and_log_err(cx);
509}
510
511fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
512    const MAX_LINES: usize = 1000;
513    workspace
514        .with_local_workspace(cx, move |workspace, cx| {
515            let fs = workspace.app_state().fs.clone();
516            cx.spawn(|workspace, mut cx| async move {
517                let (old_log, new_log) =
518                    futures::join!(fs.load(&paths::OLD_LOG), fs.load(&paths::LOG));
519
520                let mut lines = VecDeque::with_capacity(MAX_LINES);
521                for line in old_log
522                    .iter()
523                    .flat_map(|log| log.lines())
524                    .chain(new_log.iter().flat_map(|log| log.lines()))
525                {
526                    if lines.len() == MAX_LINES {
527                        lines.pop_front();
528                    }
529                    lines.push_back(line);
530                }
531                let log = lines
532                    .into_iter()
533                    .flat_map(|line| [line, "\n"])
534                    .collect::<String>();
535
536                workspace
537                    .update(&mut cx, |workspace, cx| {
538                        let project = workspace.project().clone();
539                        let buffer = project
540                            .update(cx, |project, cx| project.create_buffer("", None, cx))
541                            .expect("creating buffers on a local workspace always succeeds");
542                        buffer.update(cx, |buffer, cx| buffer.edit([(0..0, log)], None, cx));
543
544                        let buffer = cx.build_model(|cx| {
545                            MultiBuffer::singleton(buffer, cx).with_title("Log".into())
546                        });
547                        workspace.add_item(
548                            Box::new(cx.build_view(|cx| {
549                                Editor::for_multibuffer(buffer, Some(project), cx)
550                            })),
551                            cx,
552                        );
553                    })
554                    .log_err();
555            })
556            .detach();
557        })
558        .detach();
559}
560
561fn open_local_settings_file(
562    workspace: &mut Workspace,
563    _: &OpenLocalSettings,
564    cx: &mut ViewContext<Workspace>,
565) {
566    let project = workspace.project().clone();
567    let worktree = project
568        .read(cx)
569        .visible_worktrees(cx)
570        .find_map(|tree| tree.read(cx).root_entry()?.is_dir().then_some(tree));
571    if let Some(worktree) = worktree {
572        let tree_id = worktree.read(cx).id();
573        cx.spawn(|workspace, mut cx| async move {
574            let file_path = &*LOCAL_SETTINGS_RELATIVE_PATH;
575
576            if let Some(dir_path) = file_path.parent() {
577                if worktree.update(&mut cx, |tree, _| tree.entry_for_path(dir_path).is_none())? {
578                    project
579                        .update(&mut cx, |project, cx| {
580                            project.create_entry((tree_id, dir_path), true, cx)
581                        })?
582                        .ok_or_else(|| anyhow!("worktree was removed"))?
583                        .await?;
584                }
585            }
586
587            if worktree.update(&mut cx, |tree, _| tree.entry_for_path(file_path).is_none())? {
588                project
589                    .update(&mut cx, |project, cx| {
590                        project.create_entry((tree_id, file_path), false, cx)
591                    })?
592                    .ok_or_else(|| anyhow!("worktree was removed"))?
593                    .await?;
594            }
595
596            let editor = workspace
597                .update(&mut cx, |workspace, cx| {
598                    workspace.open_path((tree_id, file_path), None, true, cx)
599                })?
600                .await?
601                .downcast::<Editor>()
602                .ok_or_else(|| anyhow!("unexpected item type"))?;
603
604            editor
605                .downgrade()
606                .update(&mut cx, |editor, cx| {
607                    if let Some(buffer) = editor.buffer().read(cx).as_singleton() {
608                        if buffer.read(cx).is_empty() {
609                            buffer.update(cx, |buffer, cx| {
610                                buffer.edit([(0..0, initial_local_settings_content())], None, cx)
611                            });
612                        }
613                    }
614                })
615                .ok();
616
617            anyhow::Ok(())
618        })
619        .detach();
620    } else {
621        workspace.show_notification(0, cx, |cx| {
622            cx.build_view(|_| MessageNotification::new("This project has no folders open."))
623        })
624    }
625}
626
627fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
628    workspace.with_local_workspace(cx, move |workspace, cx| {
629        let app_state = workspace.app_state().clone();
630        cx.spawn(|workspace, mut cx| async move {
631            async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
632                let path = app_state.client.telemetry().log_file_path()?;
633                app_state.fs.load(&path).await.log_err()
634            }
635
636            let log = fetch_log_string(&app_state).await.unwrap_or_else(|| "// No data has been collected yet".to_string());
637
638            const MAX_TELEMETRY_LOG_LEN: usize = 5 * 1024 * 1024;
639            let mut start_offset = log.len().saturating_sub(MAX_TELEMETRY_LOG_LEN);
640            if let Some(newline_offset) = log[start_offset..].find('\n') {
641                start_offset += newline_offset + 1;
642            }
643            let log_suffix = &log[start_offset..];
644            let json = app_state.languages.language_for_name("JSON").await.log_err();
645
646            workspace.update(&mut cx, |workspace, cx| {
647                let project = workspace.project().clone();
648                let buffer = project
649                    .update(cx, |project, cx| project.create_buffer("", None, cx))
650                    .expect("creating buffers on a local workspace always succeeds");
651                buffer.update(cx, |buffer, cx| {
652                    buffer.set_language(json, cx);
653                    buffer.edit(
654                        [(
655                            0..0,
656                            concat!(
657                                "// Zed collects anonymous usage data to help us understand how people are using the app.\n",
658                                "// Telemetry can be disabled via the `settings.json` file.\n",
659                                "// Here is the data that has been reported for the current session:\n",
660                                "\n"
661                            ),
662                        )],
663                        None,
664                        cx,
665                    );
666                    buffer.edit([(buffer.len()..buffer.len(), log_suffix)], None, cx);
667                });
668
669                let buffer = cx.build_model(|cx| {
670                    MultiBuffer::singleton(buffer, cx).with_title("Telemetry Log".into())
671                });
672                workspace.add_item(
673                    Box::new(cx.build_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx))),
674                    cx,
675                );
676            }).log_err()?;
677
678            Some(())
679        })
680        .detach();
681    }).detach();
682}
683
684fn open_bundled_file(
685    workspace: &mut Workspace,
686    text: Cow<'static, str>,
687    title: &'static str,
688    language: &'static str,
689    cx: &mut ViewContext<Workspace>,
690) {
691    let language = workspace.app_state().languages.language_for_name(language);
692    cx.spawn(|workspace, mut cx| async move {
693        let language = language.await.log_err();
694        workspace
695            .update(&mut cx, |workspace, cx| {
696                workspace.with_local_workspace(cx, |workspace, cx| {
697                    let project = workspace.project();
698                    let buffer = project.update(cx, move |project, cx| {
699                        project
700                            .create_buffer(text.as_ref(), language, cx)
701                            .expect("creating buffers on a local workspace always succeeds")
702                    });
703                    let buffer = cx.build_model(|cx| {
704                        MultiBuffer::singleton(buffer, cx).with_title(title.into())
705                    });
706                    workspace.add_item(
707                        Box::new(cx.build_view(|cx| {
708                            Editor::for_multibuffer(buffer, Some(project.clone()), cx)
709                        })),
710                        cx,
711                    );
712                })
713            })?
714            .await
715    })
716    .detach_and_log_err(cx);
717}