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