From 82f793144e4bfa25ede9bf9c81344635099ae5a2 Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Thu, 27 Feb 2025 15:52:45 -0300 Subject: [PATCH] edit predictions: Add `enabled_in_assistant` setting (#25767) Release Notes: - edit predictions: Add `enabled_in_assistant` setting --- assets/settings/default.json | 5 +++- .../src/context_editor.rs | 25 +++++++++++++++++-- crates/language/src/language_settings.rs | 15 +++++++++++ docs/src/configuring-zed.md | 6 +++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 6cf64ffd52b07c1e7864f3926e26245cad77bc9a..211e12b7ae65db3fd430def521bf40cd4e3e518c 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -846,7 +846,10 @@ // "mode": "eager" // 2. Display predictions inline only when holding a modifier key (alt by default). // "mode": "subtle" - "mode": "eager" + "mode": "eager", + // Whether edit predictions are enabled in the assistant prompt editor. + // This setting has no effect if globally disabled. + "enabled_in_assistant": true }, // Settings specific to journaling "journal": { diff --git a/crates/assistant_context_editor/src/context_editor.rs b/crates/assistant_context_editor/src/context_editor.rs index 7180635103626ee0fe05c45b6582e63bb3bd69fe..d47b800536384de6a16bd1440eb389791361d7a2 100644 --- a/crates/assistant_context_editor/src/context_editor.rs +++ b/crates/assistant_context_editor/src/context_editor.rs @@ -29,7 +29,10 @@ use gpui::{ WeakEntity, }; use indexed_docs::IndexedDocsStore; -use language::{language_settings::SoftWrap, BufferSnapshot, LspAdapterDelegate, ToOffset}; +use language::{ + language_settings::{all_language_settings, SoftWrap}, + BufferSnapshot, LspAdapterDelegate, ToOffset, +}; use language_model::{ LanguageModelImage, LanguageModelProvider, LanguageModelProviderTosView, LanguageModelRegistry, Role, @@ -41,7 +44,7 @@ use project::lsp_store::LocalLspAdapterDelegate; use project::{Project, Worktree}; use rope::Point; use serde::{Deserialize, Serialize}; -use settings::{update_settings_file, Settings}; +use settings::{update_settings_file, Settings, SettingsStore}; use std::{any::TypeId, borrow::Cow, cmp, ops::Range, path::PathBuf, sync::Arc, time::Duration}; use text::SelectionGoal; use ui::{ @@ -228,6 +231,13 @@ impl ContextEditor { editor.set_completion_provider(Some(Box::new(completion_provider))); editor.set_menu_inline_completions_policy(MenuInlineCompletionsPolicy::Never); editor.set_collaboration_hub(Box::new(project.clone())); + + let show_edit_predictions = all_language_settings(None, cx) + .edit_predictions + .enabled_in_assistant; + + editor.set_show_edit_predictions(Some(show_edit_predictions), window, cx); + editor }); @@ -236,6 +246,7 @@ impl ContextEditor { cx.subscribe_in(&context, window, Self::handle_context_event), cx.subscribe_in(&editor, window, Self::handle_editor_event), cx.subscribe_in(&editor, window, Self::handle_editor_search_event), + cx.observe_global_in::(window, Self::settings_changed), ]; let fs_clone = fs.clone(); @@ -286,6 +297,16 @@ impl ContextEditor { this } + fn settings_changed(&mut self, window: &mut Window, cx: &mut Context) { + self.editor.update(cx, |editor, cx| { + let show_edit_predictions = all_language_settings(None, cx) + .edit_predictions + .enabled_in_assistant; + + editor.set_show_edit_predictions(Some(show_edit_predictions), window, cx); + }); + } + pub fn context(&self) -> &Entity { &self.context } diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 5a27427d6ec59b557b71d6a5aee1894e1db57ea5..1b6168d75967b79c9980f4c143f98caecc6bda25 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -236,6 +236,9 @@ pub struct EditPredictionSettings { pub mode: EditPredictionsMode, /// Settings specific to GitHub Copilot. pub copilot: CopilotSettings, + /// Whether edit predictions are enabled in the assistant prompt editor. + /// This setting has no effect if globally disabled. + pub enabled_in_assistant: bool, } impl EditPredictionSettings { @@ -500,6 +503,10 @@ pub struct EditPredictionSettingsContent { /// Settings specific to GitHub Copilot. #[serde(default)] pub copilot: CopilotSettingsContent, + /// Whether edit predictions are enabled in the assistant prompt editor. + /// This has no effect if globally disabled. + #[serde(default = "default_true")] + pub enabled_in_assistant: bool, } #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)] @@ -1119,6 +1126,12 @@ impl settings::Settings for AllLanguageSettings { }) .unwrap_or_default(); + let mut edit_predictions_enabled_in_assistant = default_value + .edit_predictions + .as_ref() + .map(|settings| settings.enabled_in_assistant) + .unwrap_or(true); + let mut file_types: HashMap, GlobSet> = HashMap::default(); for (language, suffixes) in &default_value.file_types { @@ -1145,6 +1158,7 @@ impl settings::Settings for AllLanguageSettings { if let Some(edit_predictions) = user_settings.edit_predictions.as_ref() { edit_predictions_mode = edit_predictions.mode; + edit_predictions_enabled_in_assistant = edit_predictions.enabled_in_assistant; if let Some(disabled_globs) = edit_predictions.disabled_globs.as_ref() { completion_globs.extend(disabled_globs.iter()); @@ -1224,6 +1238,7 @@ impl settings::Settings for AllLanguageSettings { .collect(), mode: edit_predictions_mode, copilot: copilot_settings, + enabled_in_assistant: edit_predictions_enabled_in_assistant, }, defaults, languages, diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index 74ec806d6996bab4aff830f635b7aaa95d8fd9ce..5587f9dbfcff24ff49bfe5ae7192e9f78afbf1c8 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -406,6 +406,12 @@ There are two options to choose from: List of `string` values. +### Enabled in Assistant + +- Description: Whether to show edit predictions in the assistant's prompt editor. +- Setting: `enabled_in_assistant` +- Default: `true` + ## Edit Predictions Disabled in - Description: A list of language scopes in which edit predictions should be disabled.