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