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, PromptLevel, TitlebarOptions, ViewContext,
 14    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::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.add_view(|_| diagnostics2::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.add_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.weak_handle(), 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        //todo!()
429        // load_default_keymap(cx);
430    })
431    .detach();
432}
433
434fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {
435    let app_name = cx.global::<ReleaseChannel>().display_name();
436    let version = env!("CARGO_PKG_VERSION");
437    let prompt = cx.prompt(PromptLevel::Info, &format!("{app_name} {version}"), &["OK"]);
438    cx.foreground_executor()
439        .spawn(async {
440            prompt.await.ok();
441        })
442        .detach();
443}
444
445fn quit(_: &mut Workspace, _: &Quit, cx: &mut gpui::ViewContext<Workspace>) {
446    let should_confirm = WorkspaceSettings::get_global(cx).confirm_quit;
447    cx.spawn(|_, mut cx| async move {
448        let mut workspace_windows = cx.update(|_, cx| {
449            cx.windows()
450                .into_iter()
451                .filter_map(|window| window.downcast::<Workspace>())
452                .collect::<Vec<_>>()
453        })?;
454
455        // If multiple windows have unsaved changes, and need a save prompt,
456        // prompt in the active window before switching to a different window.
457        cx.update(|_, cx| {
458            workspace_windows.sort_by_key(|window| window.is_active(&cx) == Some(false));
459        })
460        .log_err();
461
462        if let (true, Some(window)) = (should_confirm, workspace_windows.first().copied()) {
463            let answer = cx
464                .update(|_, cx| {
465                    cx.prompt(
466                        PromptLevel::Info,
467                        "Are you sure you want to quit?",
468                        &["Quit", "Cancel"],
469                    )
470                })
471                .log_err();
472
473            if let Some(mut answer) = answer {
474                let answer = answer.await.ok();
475                if answer != Some(0) {
476                    return Ok(());
477                }
478            }
479        }
480
481        // If the user cancels any save prompt, then keep the app open.
482        for window in workspace_windows {
483            if let Some(should_close) = window
484                .update(&mut cx, |workspace, cx| {
485                    workspace.prepare_to_close(true, cx)
486                })
487                .log_err()
488            {
489                if !should_close.await? {
490                    return Ok(());
491                }
492            }
493        }
494        cx.update(|_, cx| {
495            cx.quit();
496        })?;
497        anyhow::Ok(())
498    })
499    .detach_and_log_err(cx);
500}
501
502fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
503    const MAX_LINES: usize = 1000;
504    workspace
505        .with_local_workspace(cx, move |workspace, cx| {
506            let fs = workspace.app_state().fs.clone();
507            cx.spawn(|workspace, mut cx| async move {
508                let (old_log, new_log) =
509                    futures::join!(fs.load(&paths::OLD_LOG), fs.load(&paths::LOG));
510
511                let mut lines = VecDeque::with_capacity(MAX_LINES);
512                for line in old_log
513                    .iter()
514                    .flat_map(|log| log.lines())
515                    .chain(new_log.iter().flat_map(|log| log.lines()))
516                {
517                    if lines.len() == MAX_LINES {
518                        lines.pop_front();
519                    }
520                    lines.push_back(line);
521                }
522                let log = lines
523                    .into_iter()
524                    .flat_map(|line| [line, "\n"])
525                    .collect::<String>();
526
527                workspace
528                    .update(&mut cx, |workspace, cx| {
529                        let project = workspace.project().clone();
530                        let buffer = project
531                            .update(cx, |project, cx| project.create_buffer("", None, cx))
532                            .expect("creating buffers on a local workspace always succeeds");
533                        buffer.update(cx, |buffer, cx| buffer.edit([(0..0, log)], None, cx));
534
535                        let buffer = cx.build_model(|cx| {
536                            MultiBuffer::singleton(buffer, cx).with_title("Log".into())
537                        });
538                        workspace.add_item(
539                            Box::new(cx.build_view(|cx| {
540                                Editor::for_multibuffer(buffer, Some(project), cx)
541                            })),
542                            cx,
543                        );
544                    })
545                    .log_err();
546            })
547            .detach();
548        })
549        .detach();
550}
551
552fn open_local_settings_file(
553    workspace: &mut Workspace,
554    _: &OpenLocalSettings,
555    cx: &mut ViewContext<Workspace>,
556) {
557    let project = workspace.project().clone();
558    let worktree = project
559        .read(cx)
560        .visible_worktrees(cx)
561        .find_map(|tree| tree.read(cx).root_entry()?.is_dir().then_some(tree));
562    if let Some(worktree) = worktree {
563        let tree_id = worktree.read(cx).id();
564        cx.spawn(|workspace, mut cx| async move {
565            let file_path = &*LOCAL_SETTINGS_RELATIVE_PATH;
566
567            if let Some(dir_path) = file_path.parent() {
568                if worktree.update(&mut cx, |tree, _| tree.entry_for_path(dir_path).is_none())? {
569                    project
570                        .update(&mut cx, |project, cx| {
571                            project.create_entry((tree_id, dir_path), true, cx)
572                        })?
573                        .ok_or_else(|| anyhow!("worktree was removed"))?
574                        .await?;
575                }
576            }
577
578            if worktree.update(&mut cx, |tree, _| tree.entry_for_path(file_path).is_none())? {
579                project
580                    .update(&mut cx, |project, cx| {
581                        project.create_entry((tree_id, file_path), false, cx)
582                    })?
583                    .ok_or_else(|| anyhow!("worktree was removed"))?
584                    .await?;
585            }
586
587            let editor = workspace
588                .update(&mut cx, |workspace, cx| {
589                    workspace.open_path((tree_id, file_path), None, true, cx)
590                })?
591                .await?
592                .downcast::<Editor>()
593                .ok_or_else(|| anyhow!("unexpected item type"))?;
594
595            editor
596                .downgrade()
597                .update(&mut cx, |editor, cx| {
598                    if let Some(buffer) = editor.buffer().read(cx).as_singleton() {
599                        if buffer.read(cx).is_empty() {
600                            buffer.update(cx, |buffer, cx| {
601                                buffer.edit([(0..0, initial_local_settings_content())], None, cx)
602                            });
603                        }
604                    }
605                })
606                .ok();
607
608            anyhow::Ok(())
609        })
610        .detach();
611    } else {
612        workspace.show_notification(0, cx, |cx| {
613            cx.build_view(|_| MessageNotification::new("This project has no folders open."))
614        })
615    }
616}
617
618fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
619    workspace.with_local_workspace(cx, move |workspace, cx| {
620        let app_state = workspace.app_state().clone();
621        cx.spawn(|workspace, mut cx| async move {
622            async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
623                let path = app_state.client.telemetry().log_file_path()?;
624                app_state.fs.load(&path).await.log_err()
625            }
626
627            let log = fetch_log_string(&app_state).await.unwrap_or_else(|| "// No data has been collected yet".to_string());
628
629            const MAX_TELEMETRY_LOG_LEN: usize = 5 * 1024 * 1024;
630            let mut start_offset = log.len().saturating_sub(MAX_TELEMETRY_LOG_LEN);
631            if let Some(newline_offset) = log[start_offset..].find('\n') {
632                start_offset += newline_offset + 1;
633            }
634            let log_suffix = &log[start_offset..];
635            let json = app_state.languages.language_for_name("JSON").await.log_err();
636
637            workspace.update(&mut cx, |workspace, cx| {
638                let project = workspace.project().clone();
639                let buffer = project
640                    .update(cx, |project, cx| project.create_buffer("", None, cx))
641                    .expect("creating buffers on a local workspace always succeeds");
642                buffer.update(cx, |buffer, cx| {
643                    buffer.set_language(json, cx);
644                    buffer.edit(
645                        [(
646                            0..0,
647                            concat!(
648                                "// Zed collects anonymous usage data to help us understand how people are using the app.\n",
649                                "// Telemetry can be disabled via the `settings.json` file.\n",
650                                "// Here is the data that has been reported for the current session:\n",
651                                "\n"
652                            ),
653                        )],
654                        None,
655                        cx,
656                    );
657                    buffer.edit([(buffer.len()..buffer.len(), log_suffix)], None, cx);
658                });
659
660                let buffer = cx.build_model(|cx| {
661                    MultiBuffer::singleton(buffer, cx).with_title("Telemetry Log".into())
662                });
663                workspace.add_item(
664                    Box::new(cx.build_view(|cx| Editor::for_multibuffer(buffer, Some(project), cx))),
665                    cx,
666                );
667            }).log_err()?;
668
669            Some(())
670        })
671        .detach();
672    }).detach();
673}
674
675fn open_bundled_file(
676    workspace: &mut Workspace,
677    text: Cow<'static, str>,
678    title: &'static str,
679    language: &'static str,
680    cx: &mut ViewContext<Workspace>,
681) {
682    let language = workspace.app_state().languages.language_for_name(language);
683    cx.spawn(|workspace, mut cx| async move {
684        let language = language.await.log_err();
685        workspace
686            .update(&mut cx, |workspace, cx| {
687                workspace.with_local_workspace(cx, |workspace, cx| {
688                    let project = workspace.project();
689                    let buffer = project.update(cx, move |project, cx| {
690                        project
691                            .create_buffer(text.as_ref(), language, cx)
692                            .expect("creating buffers on a local workspace always succeeds")
693                    });
694                    let buffer = cx.build_model(|cx| {
695                        MultiBuffer::singleton(buffer, cx).with_title(title.into())
696                    });
697                    workspace.add_item(
698                        Box::new(cx.build_view(|cx| {
699                            Editor::for_multibuffer(buffer, Some(project.clone()), cx)
700                        })),
701                        cx,
702                    );
703                })
704            })?
705            .await
706    })
707    .detach_and_log_err(cx);
708}