1use anyhow::Result;
2use client::UserStore;
3use copilot::{Copilot, Status};
4use editor::{
5 actions::{ShowEditPrediction, ToggleEditPrediction},
6 scroll::Autoscroll,
7 Editor,
8};
9use feature_flags::{
10 FeatureFlagAppExt, PredictEditsFeatureFlag, PredictEditsRateCompletionsFeatureFlag,
11};
12use fs::Fs;
13use gpui::{
14 actions, div, pulsating_between, Action, Animation, AnimationExt, App, AsyncWindowContext,
15 Corner, Entity, FocusHandle, Focusable, IntoElement, ParentElement, Render, Subscription,
16 WeakEntity,
17};
18use indoc::indoc;
19use language::{
20 language_settings::{self, all_language_settings, AllLanguageSettings, EditPredictionProvider},
21 File, Language,
22};
23use regex::Regex;
24use settings::{update_settings_file, Settings, SettingsStore};
25use std::{
26 sync::{Arc, LazyLock},
27 time::Duration,
28};
29use supermaven::{AccountStatus, Supermaven};
30use ui::{
31 prelude::*, Clickable, ContextMenu, ContextMenuEntry, IconButton, IconButtonShape, Indicator,
32 PopoverMenu, PopoverMenuHandle, Tooltip,
33};
34use workspace::{
35 create_and_open_local_file, item::ItemHandle, notifications::NotificationId, StatusItemView,
36 Toast, Workspace,
37};
38use zed_actions::OpenBrowser;
39use zeta::RateCompletions;
40
41actions!(edit_prediction, [ToggleMenu]);
42
43const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
44
45struct CopilotErrorToast;
46
47pub struct InlineCompletionButton {
48 editor_subscription: Option<(Subscription, usize)>,
49 editor_enabled: Option<bool>,
50 editor_show_predictions: bool,
51 editor_focus_handle: Option<FocusHandle>,
52 language: Option<Arc<Language>>,
53 file: Option<Arc<dyn File>>,
54 edit_prediction_provider: Option<Arc<dyn inline_completion::InlineCompletionProviderHandle>>,
55 fs: Arc<dyn Fs>,
56 user_store: Entity<UserStore>,
57 popover_menu_handle: PopoverMenuHandle<ContextMenu>,
58}
59
60enum SupermavenButtonStatus {
61 Ready,
62 Errored(String),
63 NeedsActivation(String),
64 Initializing,
65}
66
67impl Render for InlineCompletionButton {
68 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
69 let all_language_settings = all_language_settings(None, cx);
70
71 match all_language_settings.edit_predictions.provider {
72 EditPredictionProvider::None => div(),
73
74 EditPredictionProvider::Copilot => {
75 let Some(copilot) = Copilot::global(cx) else {
76 return div();
77 };
78 let status = copilot.read(cx).status();
79
80 let enabled = self.editor_enabled.unwrap_or(false);
81
82 let icon = match status {
83 Status::Error(_) => IconName::CopilotError,
84 Status::Authorized => {
85 if enabled {
86 IconName::Copilot
87 } else {
88 IconName::CopilotDisabled
89 }
90 }
91 _ => IconName::CopilotInit,
92 };
93
94 if let Status::Error(e) = status {
95 return div().child(
96 IconButton::new("copilot-error", icon)
97 .icon_size(IconSize::Small)
98 .on_click(cx.listener(move |_, _, window, cx| {
99 if let Some(workspace) = window.root::<Workspace>().flatten() {
100 workspace.update(cx, |workspace, cx| {
101 workspace.show_toast(
102 Toast::new(
103 NotificationId::unique::<CopilotErrorToast>(),
104 format!("Copilot can't be started: {}", e),
105 )
106 .on_click(
107 "Reinstall Copilot",
108 |_, cx| {
109 if let Some(copilot) = Copilot::global(cx) {
110 copilot
111 .update(cx, |copilot, cx| {
112 copilot.reinstall(cx)
113 })
114 .detach();
115 }
116 },
117 ),
118 cx,
119 );
120 });
121 }
122 }))
123 .tooltip(|window, cx| {
124 Tooltip::for_action("GitHub Copilot", &ToggleMenu, window, cx)
125 }),
126 );
127 }
128 let this = cx.entity().clone();
129
130 div().child(
131 PopoverMenu::new("copilot")
132 .menu(move |window, cx| {
133 Some(match status {
134 Status::Authorized => this.update(cx, |this, cx| {
135 this.build_copilot_context_menu(window, cx)
136 }),
137 _ => this.update(cx, |this, cx| {
138 this.build_copilot_start_menu(window, cx)
139 }),
140 })
141 })
142 .anchor(Corner::BottomRight)
143 .trigger_with_tooltip(
144 IconButton::new("copilot-icon", icon),
145 |window, cx| {
146 Tooltip::for_action("GitHub Copilot", &ToggleMenu, window, cx)
147 },
148 )
149 .with_handle(self.popover_menu_handle.clone()),
150 )
151 }
152
153 EditPredictionProvider::Supermaven => {
154 let Some(supermaven) = Supermaven::global(cx) else {
155 return div();
156 };
157
158 let supermaven = supermaven.read(cx);
159
160 let status = match supermaven {
161 Supermaven::Starting => SupermavenButtonStatus::Initializing,
162 Supermaven::FailedDownload { error } => {
163 SupermavenButtonStatus::Errored(error.to_string())
164 }
165 Supermaven::Spawned(agent) => {
166 let account_status = agent.account_status.clone();
167 match account_status {
168 AccountStatus::NeedsActivation { activate_url } => {
169 SupermavenButtonStatus::NeedsActivation(activate_url.clone())
170 }
171 AccountStatus::Unknown => SupermavenButtonStatus::Initializing,
172 AccountStatus::Ready => SupermavenButtonStatus::Ready,
173 }
174 }
175 Supermaven::Error { error } => {
176 SupermavenButtonStatus::Errored(error.to_string())
177 }
178 };
179
180 let icon = status.to_icon();
181 let tooltip_text = status.to_tooltip();
182 let has_menu = status.has_menu();
183 let this = cx.entity().clone();
184 let fs = self.fs.clone();
185
186 return div().child(
187 PopoverMenu::new("supermaven")
188 .menu(move |window, cx| match &status {
189 SupermavenButtonStatus::NeedsActivation(activate_url) => {
190 Some(ContextMenu::build(window, cx, |menu, _, _| {
191 let fs = fs.clone();
192 let activate_url = activate_url.clone();
193 menu.entry("Sign In", None, move |_, cx| {
194 cx.open_url(activate_url.as_str())
195 })
196 .entry(
197 "Use Copilot",
198 None,
199 move |_, cx| {
200 set_completion_provider(
201 fs.clone(),
202 cx,
203 EditPredictionProvider::Copilot,
204 )
205 },
206 )
207 }))
208 }
209 SupermavenButtonStatus::Ready => Some(this.update(cx, |this, cx| {
210 this.build_supermaven_context_menu(window, cx)
211 })),
212 _ => None,
213 })
214 .anchor(Corner::BottomRight)
215 .trigger_with_tooltip(
216 IconButton::new("supermaven-icon", icon),
217 move |window, cx| {
218 if has_menu {
219 Tooltip::for_action(
220 tooltip_text.clone(),
221 &ToggleMenu,
222 window,
223 cx,
224 )
225 } else {
226 Tooltip::text(tooltip_text.clone())(window, cx)
227 }
228 },
229 )
230 .with_handle(self.popover_menu_handle.clone()),
231 );
232 }
233
234 EditPredictionProvider::Zed => {
235 if !cx.has_flag::<PredictEditsFeatureFlag>() {
236 return div();
237 }
238
239 let enabled = self.editor_enabled.unwrap_or(true);
240
241 let zeta_icon = if enabled {
242 IconName::ZedPredict
243 } else {
244 IconName::ZedPredictDisabled
245 };
246
247 let current_user_terms_accepted =
248 self.user_store.read(cx).current_user_has_accepted_terms();
249
250 if !current_user_terms_accepted.unwrap_or(false) {
251 let signed_in = current_user_terms_accepted.is_some();
252 let tooltip_meta = if signed_in {
253 "Read Terms of Service"
254 } else {
255 "Sign in to use"
256 };
257
258 return div().child(
259 IconButton::new("zed-predict-pending-button", zeta_icon)
260 .shape(IconButtonShape::Square)
261 .indicator(Indicator::dot().color(Color::Error))
262 .indicator_border_color(Some(cx.theme().colors().status_bar_background))
263 .tooltip(move |window, cx| {
264 Tooltip::with_meta(
265 "Edit Predictions",
266 None,
267 tooltip_meta,
268 window,
269 cx,
270 )
271 })
272 .on_click(cx.listener(move |_, _, window, cx| {
273 telemetry::event!(
274 "Pending ToS Clicked",
275 source = "Edit Prediction Status Button"
276 );
277 window.dispatch_action(
278 zed_actions::OpenZedPredictOnboarding.boxed_clone(),
279 cx,
280 );
281 })),
282 );
283 }
284
285 let show_editor_predictions = self.editor_show_predictions;
286
287 let icon_button = IconButton::new("zed-predict-pending-button", zeta_icon)
288 .shape(IconButtonShape::Square)
289 .when(enabled && !show_editor_predictions, |this| {
290 this.indicator(Indicator::dot().color(Color::Muted))
291 .indicator_border_color(Some(cx.theme().colors().status_bar_background))
292 })
293 .when(!self.popover_menu_handle.is_deployed(), |element| {
294 element.tooltip(move |window, cx| {
295 if enabled {
296 if show_editor_predictions {
297 Tooltip::for_action("Edit Prediction", &ToggleMenu, window, cx)
298 } else {
299 Tooltip::with_meta(
300 "Edit Prediction",
301 Some(&ToggleMenu),
302 "Hidden For This File",
303 window,
304 cx,
305 )
306 }
307 } else {
308 Tooltip::with_meta(
309 "Edit Prediction",
310 Some(&ToggleMenu),
311 "Disabled For This File",
312 window,
313 cx,
314 )
315 }
316 })
317 });
318
319 let this = cx.entity().clone();
320
321 let mut popover_menu = PopoverMenu::new("zeta")
322 .menu(move |window, cx| {
323 Some(this.update(cx, |this, cx| this.build_zeta_context_menu(window, cx)))
324 })
325 .anchor(Corner::BottomRight)
326 .with_handle(self.popover_menu_handle.clone());
327
328 let is_refreshing = self
329 .edit_prediction_provider
330 .as_ref()
331 .map_or(false, |provider| provider.is_refreshing(cx));
332
333 if is_refreshing {
334 popover_menu = popover_menu.trigger(
335 icon_button.with_animation(
336 "pulsating-label",
337 Animation::new(Duration::from_secs(2))
338 .repeat()
339 .with_easing(pulsating_between(0.2, 1.0)),
340 |icon_button, delta| icon_button.alpha(delta),
341 ),
342 );
343 } else {
344 popover_menu = popover_menu.trigger(icon_button);
345 }
346
347 div().child(popover_menu.into_any_element())
348 }
349 }
350 }
351}
352
353impl InlineCompletionButton {
354 pub fn new(
355 fs: Arc<dyn Fs>,
356 user_store: Entity<UserStore>,
357 popover_menu_handle: PopoverMenuHandle<ContextMenu>,
358 cx: &mut Context<Self>,
359 ) -> Self {
360 if let Some(copilot) = Copilot::global(cx) {
361 cx.observe(&copilot, |_, _, cx| cx.notify()).detach()
362 }
363
364 cx.observe_global::<SettingsStore>(move |_, cx| cx.notify())
365 .detach();
366
367 Self {
368 editor_subscription: None,
369 editor_enabled: None,
370 editor_show_predictions: true,
371 editor_focus_handle: None,
372 language: None,
373 file: None,
374 edit_prediction_provider: None,
375 popover_menu_handle,
376 fs,
377 user_store,
378 }
379 }
380
381 pub fn build_copilot_start_menu(
382 &mut self,
383 window: &mut Window,
384 cx: &mut Context<Self>,
385 ) -> Entity<ContextMenu> {
386 let fs = self.fs.clone();
387 ContextMenu::build(window, cx, |menu, _, _| {
388 menu.entry("Sign In", None, copilot::initiate_sign_in)
389 .entry("Disable Copilot", None, {
390 let fs = fs.clone();
391 move |_window, cx| hide_copilot(fs.clone(), cx)
392 })
393 .entry("Use Supermaven", None, {
394 let fs = fs.clone();
395 move |_window, cx| {
396 set_completion_provider(fs.clone(), cx, EditPredictionProvider::Supermaven)
397 }
398 })
399 })
400 }
401
402 pub fn build_language_settings_menu(&self, mut menu: ContextMenu, cx: &mut App) -> ContextMenu {
403 let fs = self.fs.clone();
404
405 menu = menu.header("Show Edit Predictions For");
406
407 if let Some(editor_focus_handle) = self.editor_focus_handle.clone() {
408 menu = menu.toggleable_entry(
409 "This File",
410 self.editor_show_predictions,
411 IconPosition::Start,
412 Some(Box::new(ToggleEditPrediction)),
413 {
414 let editor_focus_handle = editor_focus_handle.clone();
415 move |window, cx| {
416 editor_focus_handle.dispatch_action(&ToggleEditPrediction, window, cx);
417 }
418 },
419 );
420 }
421
422 if let Some(language) = self.language.clone() {
423 let fs = fs.clone();
424 let language_enabled =
425 language_settings::language_settings(Some(language.name()), None, cx)
426 .show_edit_predictions;
427
428 menu = menu.toggleable_entry(
429 language.name(),
430 language_enabled,
431 IconPosition::Start,
432 None,
433 move |_, cx| {
434 toggle_show_inline_completions_for_language(language.clone(), fs.clone(), cx)
435 },
436 );
437 }
438
439 let settings = AllLanguageSettings::get_global(cx);
440 let globally_enabled = settings.show_inline_completions(None, cx);
441 menu = menu.toggleable_entry("All Files", globally_enabled, IconPosition::Start, None, {
442 let fs = fs.clone();
443 move |_, cx| toggle_inline_completions_globally(fs.clone(), cx)
444 });
445 menu = menu.separator().header("Privacy Settings");
446
447 if let Some(provider) = &self.edit_prediction_provider {
448 let data_collection = provider.data_collection_state(cx);
449 if data_collection.is_supported() {
450 let provider = provider.clone();
451 let enabled = data_collection.is_enabled();
452 let is_open_source = data_collection.is_project_open_source();
453 let is_collecting = data_collection.is_enabled();
454
455 menu = menu.item(
456 ContextMenuEntry::new("Share Training Data")
457 .toggleable(IconPosition::Start, data_collection.is_enabled())
458 .icon_color(if is_open_source && is_collecting {
459 Color::Success
460 } else {
461 Color::Accent
462 })
463 .documentation_aside(move |cx| {
464 let (msg, label_color, icon_name, icon_color) = match (is_open_source, is_collecting) {
465 (true, true) => (
466 "Project identified as open-source, and you're sharing data.",
467 Color::Default,
468 IconName::Check,
469 Color::Success,
470 ),
471 (true, false) => (
472 "Project identified as open-source, but you're not sharing data.",
473 Color::Muted,
474 IconName::XCircle,
475 Color::Muted,
476 ),
477 (false, _) => (
478 "Project not identified as open-source. No data captured.",
479 Color::Muted,
480 IconName::XCircle,
481 Color::Muted,
482 ),
483 };
484 v_flex()
485 .gap_2()
486 .child(
487 Label::new(indoc!{
488 "Help us improve our open model by sharing data from open source repositories. \
489 Zed must detect a license file in your repo for this setting to take effect."
490 })
491 )
492 .child(
493 h_flex()
494 .pt_2()
495 .gap_1p5()
496 .border_t_1()
497 .border_color(cx.theme().colors().border_variant)
498 .child(Icon::new(icon_name).size(IconSize::XSmall).color(icon_color))
499 .child(div().child(Label::new(msg).size(LabelSize::Small).color(label_color)))
500 )
501 .into_any_element()
502 })
503 .handler(move |_, cx| {
504 provider.toggle_data_collection(cx);
505
506 if !enabled {
507 telemetry::event!(
508 "Data Collection Enabled",
509 source = "Edit Prediction Status Menu"
510 );
511 } else {
512 telemetry::event!(
513 "Data Collection Disabled",
514 source = "Edit Prediction Status Menu"
515 );
516 }
517 })
518 );
519 }
520 }
521
522 menu = menu.item(
523 ContextMenuEntry::new("Configure Excluded Files")
524 .icon(IconName::LockOutlined)
525 .icon_color(Color::Muted)
526 .documentation_aside(|_| {
527 Label::new(indoc!{"
528 Open your settings to add sensitive paths for which Zed will never predict edits."}).into_any_element()
529 })
530 .handler(move |window, cx| {
531 if let Some(workspace) = window.root().flatten() {
532 let workspace = workspace.downgrade();
533 window
534 .spawn(cx, |cx| {
535 open_disabled_globs_setting_in_editor(
536 workspace,
537 cx,
538 )
539 })
540 .detach_and_log_err(cx);
541 }
542 }),
543 );
544
545 if !self.editor_enabled.unwrap_or(true) {
546 menu = menu.item(
547 ContextMenuEntry::new("This file is excluded.")
548 .disabled(true)
549 .icon(IconName::ZedPredictDisabled)
550 .icon_size(IconSize::Small),
551 );
552 }
553
554 let is_eager_preview_enabled = match settings.edit_predictions_mode() {
555 language::EditPredictionsMode::Auto => false,
556 language::EditPredictionsMode::EagerPreview => true,
557 };
558 menu = menu.separator().toggleable_entry(
559 "Eager Preview",
560 is_eager_preview_enabled,
561 IconPosition::Start,
562 None,
563 {
564 let fs = fs.clone();
565 move |_window, cx| {
566 update_settings_file::<AllLanguageSettings>(
567 fs.clone(),
568 cx,
569 move |settings, _cx| {
570 let new_mode = match is_eager_preview_enabled {
571 true => language::EditPredictionsMode::Auto,
572 false => language::EditPredictionsMode::EagerPreview,
573 };
574
575 if let Some(edit_predictions) = settings.edit_predictions.as_mut() {
576 edit_predictions.mode = new_mode;
577 } else {
578 settings.edit_predictions =
579 Some(language_settings::EditPredictionSettingsContent {
580 mode: new_mode,
581 ..Default::default()
582 });
583 }
584 },
585 );
586 }
587 },
588 );
589
590 if let Some(editor_focus_handle) = self.editor_focus_handle.clone() {
591 menu = menu
592 .separator()
593 .entry(
594 "Predict Edit at Cursor",
595 Some(Box::new(ShowEditPrediction)),
596 {
597 let editor_focus_handle = editor_focus_handle.clone();
598 move |window, cx| {
599 editor_focus_handle.dispatch_action(&ShowEditPrediction, window, cx);
600 }
601 },
602 )
603 .context(editor_focus_handle);
604 }
605
606 menu
607 }
608
609 fn build_copilot_context_menu(
610 &self,
611 window: &mut Window,
612 cx: &mut Context<Self>,
613 ) -> Entity<ContextMenu> {
614 ContextMenu::build(window, cx, |menu, _, cx| {
615 self.build_language_settings_menu(menu, cx)
616 .separator()
617 .link(
618 "Go to Copilot Settings",
619 OpenBrowser {
620 url: COPILOT_SETTINGS_URL.to_string(),
621 }
622 .boxed_clone(),
623 )
624 .action("Sign Out", copilot::SignOut.boxed_clone())
625 })
626 }
627
628 fn build_supermaven_context_menu(
629 &self,
630 window: &mut Window,
631 cx: &mut Context<Self>,
632 ) -> Entity<ContextMenu> {
633 ContextMenu::build(window, cx, |menu, _, cx| {
634 self.build_language_settings_menu(menu, cx)
635 .separator()
636 .action("Sign Out", supermaven::SignOut.boxed_clone())
637 })
638 }
639
640 fn build_zeta_context_menu(
641 &self,
642 window: &mut Window,
643 cx: &mut Context<Self>,
644 ) -> Entity<ContextMenu> {
645 ContextMenu::build(window, cx, |menu, _window, cx| {
646 self.build_language_settings_menu(menu, cx).when(
647 cx.has_flag::<PredictEditsRateCompletionsFeatureFlag>(),
648 |this| this.action("Rate Completions", RateCompletions.boxed_clone()),
649 )
650 })
651 }
652
653 pub fn update_enabled(&mut self, editor: Entity<Editor>, cx: &mut Context<Self>) {
654 let editor = editor.read(cx);
655 let snapshot = editor.buffer().read(cx).snapshot(cx);
656 let suggestion_anchor = editor.selections.newest_anchor().start;
657 let language = snapshot.language_at(suggestion_anchor);
658 let file = snapshot.file_at(suggestion_anchor).cloned();
659 self.editor_enabled = {
660 let file = file.as_ref();
661 Some(
662 file.map(|file| {
663 all_language_settings(Some(file), cx)
664 .inline_completions_enabled_for_path(file.path())
665 })
666 .unwrap_or(true),
667 )
668 };
669 self.editor_show_predictions = editor.edit_predictions_enabled();
670 self.edit_prediction_provider = editor.edit_prediction_provider();
671 self.language = language.cloned();
672 self.file = file;
673 self.editor_focus_handle = Some(editor.focus_handle(cx));
674
675 cx.notify();
676 }
677
678 pub fn toggle_menu(&mut self, window: &mut Window, cx: &mut Context<Self>) {
679 self.popover_menu_handle.toggle(window, cx);
680 }
681}
682
683impl StatusItemView for InlineCompletionButton {
684 fn set_active_pane_item(
685 &mut self,
686 item: Option<&dyn ItemHandle>,
687 _: &mut Window,
688 cx: &mut Context<Self>,
689 ) {
690 if let Some(editor) = item.and_then(|item| item.act_as::<Editor>(cx)) {
691 self.editor_subscription = Some((
692 cx.observe(&editor, Self::update_enabled),
693 editor.entity_id().as_u64() as usize,
694 ));
695 self.update_enabled(editor, cx);
696 } else {
697 self.language = None;
698 self.editor_subscription = None;
699 self.editor_enabled = None;
700 }
701 cx.notify();
702 }
703}
704
705impl SupermavenButtonStatus {
706 fn to_icon(&self) -> IconName {
707 match self {
708 SupermavenButtonStatus::Ready => IconName::Supermaven,
709 SupermavenButtonStatus::Errored(_) => IconName::SupermavenError,
710 SupermavenButtonStatus::NeedsActivation(_) => IconName::SupermavenInit,
711 SupermavenButtonStatus::Initializing => IconName::SupermavenInit,
712 }
713 }
714
715 fn to_tooltip(&self) -> String {
716 match self {
717 SupermavenButtonStatus::Ready => "Supermaven is ready".to_string(),
718 SupermavenButtonStatus::Errored(error) => format!("Supermaven error: {}", error),
719 SupermavenButtonStatus::NeedsActivation(_) => "Supermaven needs activation".to_string(),
720 SupermavenButtonStatus::Initializing => "Supermaven initializing".to_string(),
721 }
722 }
723
724 fn has_menu(&self) -> bool {
725 match self {
726 SupermavenButtonStatus::Ready | SupermavenButtonStatus::NeedsActivation(_) => true,
727 SupermavenButtonStatus::Errored(_) | SupermavenButtonStatus::Initializing => false,
728 }
729 }
730}
731
732async fn open_disabled_globs_setting_in_editor(
733 workspace: WeakEntity<Workspace>,
734 mut cx: AsyncWindowContext,
735) -> Result<()> {
736 let settings_editor = workspace
737 .update_in(&mut cx, |_, window, cx| {
738 create_and_open_local_file(paths::settings_file(), window, cx, || {
739 settings::initial_user_settings_content().as_ref().into()
740 })
741 })?
742 .await?
743 .downcast::<Editor>()
744 .unwrap();
745
746 settings_editor
747 .downgrade()
748 .update_in(&mut cx, |item, window, cx| {
749 let text = item.buffer().read(cx).snapshot(cx).text();
750
751 let settings = cx.global::<SettingsStore>();
752
753 // Ensure that we always have "inline_completions { "disabled_globs": [] }"
754 let edits = settings.edits_for_update::<AllLanguageSettings>(&text, |file| {
755 file.edit_predictions
756 .get_or_insert_with(Default::default)
757 .disabled_globs
758 .get_or_insert_with(Vec::new);
759 });
760
761 if !edits.is_empty() {
762 item.edit(edits.iter().cloned(), cx);
763 }
764
765 let text = item.buffer().read(cx).snapshot(cx).text();
766
767 static DISABLED_GLOBS_REGEX: LazyLock<Regex> = LazyLock::new(|| {
768 Regex::new(r#""disabled_globs":\s*\[\s*(?P<content>(?:.|\n)*?)\s*\]"#).unwrap()
769 });
770 // Only capture [...]
771 let range = DISABLED_GLOBS_REGEX.captures(&text).and_then(|captures| {
772 captures
773 .name("content")
774 .map(|inner_match| inner_match.start()..inner_match.end())
775 });
776 if let Some(range) = range {
777 item.change_selections(Some(Autoscroll::newest()), window, cx, |selections| {
778 selections.select_ranges(vec![range]);
779 });
780 }
781 })?;
782
783 anyhow::Ok(())
784}
785
786fn toggle_inline_completions_globally(fs: Arc<dyn Fs>, cx: &mut App) {
787 let show_edit_predictions = all_language_settings(None, cx).show_inline_completions(None, cx);
788 update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
789 file.defaults.show_edit_predictions = Some(!show_edit_predictions)
790 });
791}
792
793fn set_completion_provider(fs: Arc<dyn Fs>, cx: &mut App, provider: EditPredictionProvider) {
794 update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
795 file.features
796 .get_or_insert(Default::default())
797 .edit_prediction_provider = Some(provider);
798 });
799}
800
801fn toggle_show_inline_completions_for_language(
802 language: Arc<Language>,
803 fs: Arc<dyn Fs>,
804 cx: &mut App,
805) {
806 let show_edit_predictions =
807 all_language_settings(None, cx).show_inline_completions(Some(&language), cx);
808 update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
809 file.languages
810 .entry(language.name())
811 .or_default()
812 .show_edit_predictions = Some(!show_edit_predictions);
813 });
814}
815
816fn hide_copilot(fs: Arc<dyn Fs>, cx: &mut App) {
817 update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
818 file.features
819 .get_or_insert(Default::default())
820 .edit_prediction_provider = Some(EditPredictionProvider::None);
821 });
822}