edit predictions: Add enabled_in_assistant setting (#25767)

Release Notes:

- edit predictions: Add `enabled_in_assistant` setting
This commit is contained in:
Agus Zubiaga 2025-02-27 15:52:45 -03:00 committed by GitHub
parent 6eb2ffe77a
commit 82f793144e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 3 deletions

View file

@ -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": {

View file

@ -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::<SettingsStore>(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>) {
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<AssistantContext> {
&self.context
}

View file

@ -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<Arc<str>, 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,

View file

@ -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.