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