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