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