edit predictions: Invalidate cached settings and unset provider when set to none (#25505)

Fixes a few state mismatches when changing providers and other settings

Release Notes:

- edit predictions: Fix mismatch between status bar settings and editor
control settings
- edit predictions: Turn off as soon as `edit_prediction_provider` is
set to `none`

---------

Co-authored-by: Danilo <danilo@zed.dev>
Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
Agus Zubiaga 2025-02-24 22:56:28 -03:00 committed by GitHub
parent 20440f83e9
commit 3f168e85c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 72 deletions

View file

@ -9,7 +9,7 @@ use settings::SettingsStore;
use std::{cell::RefCell, rc::Rc, sync::Arc};
use supermaven::{Supermaven, SupermavenCompletionProvider};
use ui::Window;
use zeta::ProviderDataCollection;
use zeta::{ProviderDataCollection, ZetaInlineCompletionProvider};
pub fn init(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut App) {
let editors: Rc<RefCell<HashMap<WeakEntity<Editor>, AnyWindowHandle>>> = Rc::default();
@ -225,7 +225,9 @@ fn assign_edit_prediction_provider(
let singleton_buffer = editor.buffer().read(cx).as_singleton();
match provider {
EditPredictionProvider::None => {}
EditPredictionProvider::None => {
editor.set_edit_prediction_provider::<ZetaInlineCompletionProvider>(None, window, cx);
}
EditPredictionProvider::Copilot => {
if let Some(copilot) = Copilot::global(cx) {
if let Some(buffer) = singleton_buffer {

View file

@ -87,46 +87,21 @@ impl Render for QuickActionBar {
return div().id("empty quick action bar");
};
let (
selection_menu_enabled,
inlay_hints_enabled,
supports_inlay_hints,
inline_diagnostics_enabled,
supports_inline_diagnostics,
git_blame_inline_enabled,
show_git_blame_gutter,
auto_signature_help_enabled,
show_inline_completions,
inline_completion_enabled,
) = {
let supports_inlay_hints =
editor.update(cx, |editor, cx| editor.supports_inlay_hints(cx));
let editor = editor.read(cx);
let selection_menu_enabled = editor.selection_menu_enabled(cx);
let inlay_hints_enabled = editor.inlay_hints_enabled();
let show_inline_diagnostics = editor.show_inline_diagnostics();
let supports_inline_diagnostics = editor.inline_diagnostics_enabled();
let git_blame_inline_enabled = editor.git_blame_inline_enabled();
let show_git_blame_gutter = editor.show_git_blame_gutter();
let auto_signature_help_enabled = editor.auto_signature_help_enabled(cx);
let show_edit_predictions = editor.edit_predictions_enabled();
let inline_completion_enabled = editor.inline_completions_enabled(cx);
let supports_inlay_hints = editor.update(cx, |editor, cx| editor.supports_inlay_hints(cx));
let editor_value = editor.read(cx);
let selection_menu_enabled = editor_value.selection_menu_enabled(cx);
let inlay_hints_enabled = editor_value.inlay_hints_enabled();
let inline_diagnostics_enabled = editor_value.show_inline_diagnostics();
let supports_inline_diagnostics = editor_value.inline_diagnostics_enabled();
let git_blame_inline_enabled = editor_value.git_blame_inline_enabled();
let show_git_blame_gutter = editor_value.show_git_blame_gutter();
let auto_signature_help_enabled = editor_value.auto_signature_help_enabled(cx);
let has_edit_prediction_provider = editor_value.edit_prediction_provider().is_some();
let show_edit_predictions = editor_value.edit_predictions_enabled();
let edit_predictions_enabled_at_cursor =
editor_value.edit_predictions_enabled_at_cursor(cx);
(
selection_menu_enabled,
inlay_hints_enabled,
supports_inlay_hints,
show_inline_diagnostics,
supports_inline_diagnostics,
git_blame_inline_enabled,
show_git_blame_gutter,
auto_signature_help_enabled,
show_edit_predictions,
inline_completion_enabled,
)
};
let focus_handle = editor.read(cx).focus_handle(cx);
let focus_handle = editor_value.focus_handle(cx);
let search_button = editor.is_singleton(cx).then(|| {
QuickActionBarButton::new(
@ -328,32 +303,34 @@ impl Render for QuickActionBar {
},
);
let mut inline_completion_entry = ContextMenuEntry::new("Edit Predictions")
.toggleable(IconPosition::Start, inline_completion_enabled && show_inline_completions)
.disabled(!inline_completion_enabled)
.action(Some(
editor::actions::ToggleEditPrediction.boxed_clone(),
)).handler({
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_inline_completions(
&editor::actions::ToggleEditPrediction,
window,
cx,
);
})
.ok();
}
});
if !inline_completion_enabled {
inline_completion_entry = inline_completion_entry.documentation_aside(|_| {
Label::new("You can't toggle edit predictions for this file as it is within the excluded files list.").into_any_element()
});
}
if has_edit_prediction_provider {
let mut inline_completion_entry = ContextMenuEntry::new("Edit Predictions")
.toggleable(IconPosition::Start, edit_predictions_enabled_at_cursor && show_edit_predictions)
.disabled(!edit_predictions_enabled_at_cursor)
.action(Some(
editor::actions::ToggleEditPrediction.boxed_clone(),
)).handler({
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_edit_predictions(
&editor::actions::ToggleEditPrediction,
window,
cx,
);
})
.ok();
}
});
if !edit_predictions_enabled_at_cursor {
inline_completion_entry = inline_completion_entry.documentation_aside(|_| {
Label::new("You can't toggle edit predictions for this file as it is within the excluded files list.").into_any_element()
});
}
menu = menu.item(inline_completion_entry);
menu = menu.item(inline_completion_entry);
}
menu = menu.separator();