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