Clean up edit predictions settings (#24692)

This PR does some clean up for the edit predictions settings:

- Removed `editor.show_edit_predictions_in_menu`
- Renamed `edit_predictions.inline_preview` to `edit_predictions.mode`

Release Notes:

- N/A

---------

Co-authored-by: Agus Zubiaga <agus@zed.dev>
This commit is contained in:
Marshall Bowers 2025-02-11 16:33:31 -05:00 committed by GitHub
parent 636253d2dc
commit a2592a3a37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 36 additions and 46 deletions

View file

@ -168,9 +168,6 @@
/// Whether to show the signature help after completion or a bracket pair inserted.
/// If `auto_signature_help` is enabled, this setting will be treated as enabled also.
"show_signature_help_after_edits": false,
/// Whether to show the edit predictions next to the completions provided by a language server.
/// Only has an effect if edit prediction provider supports it.
"show_edit_predictions_in_menu": true,
// Whether to show wrap guides (vertical rulers) in the editor.
// Setting this to true will show a guide at the 'preferred_line_length' value
// if 'soft_wrap' is set to 'preferred_line_length', and will show any
@ -795,11 +792,11 @@
],
// When to show edit predictions previews in buffer.
// This setting takes two possible values:
// 1. Display inline when there are no language server completions available.
// "inline_preview": "auto"
// 2. Display inline when holding modifier key (alt by default).
// "inline_preview": "when_holding_modifier"
"inline_preview": "auto"
// 1. Display inline when holding modifier key (alt by default).
// "mode": "auto"
// 2. Display inline when there are no language server completions available.
// "mode": "eager_preview"
"mode": "auto"
},
// Settings specific to journaling
"journal": {

View file

@ -95,8 +95,8 @@ use itertools::Itertools;
use language::{
language_settings::{self, all_language_settings, language_settings, InlayHintSettings},
markdown, point_from_lsp, AutoindentMode, BracketPair, Buffer, Capability, CharKind, CodeLabel,
CompletionDocumentation, CursorShape, Diagnostic, EditPreview, HighlightedText, IndentKind,
IndentSize, InlineCompletionPreviewMode, Language, OffsetRangeExt, Point, Selection,
CompletionDocumentation, CursorShape, Diagnostic, EditPredictionsMode, EditPreview,
HighlightedText, IndentKind, IndentSize, Language, OffsetRangeExt, Point, Selection,
SelectionGoal, TextObject, TransactionId, TreeSitterOptions,
};
use language::{point_to_lsp, BufferRow, CharClassifier, Runnable, RunnableRange};
@ -5047,7 +5047,6 @@ impl Editor {
);
let show_in_menu = by_provider
&& EditorSettings::get_global(cx).show_edit_predictions_in_menu
&& self
.edit_prediction_provider
.as_ref()
@ -5055,9 +5054,8 @@ impl Editor {
provider.provider.show_completions_in_menu()
});
let preview_requires_modifier = all_language_settings(file, cx)
.inline_completions_preview_mode()
== InlineCompletionPreviewMode::WhenHoldingModifier;
let preview_requires_modifier =
all_language_settings(file, cx).edit_predictions_mode() == EditPredictionsMode::Auto;
EditPredictionSettings::Enabled {
show_in_menu,

View file

@ -35,7 +35,6 @@ pub struct EditorSettings {
pub auto_signature_help: bool,
pub show_signature_help_after_edits: bool,
pub jupyter: Jupyter,
pub show_edit_predictions_in_menu: bool,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
@ -368,12 +367,6 @@ pub struct EditorSettingsContent {
/// Default: false
pub show_signature_help_after_edits: Option<bool>,
/// Whether to show the edit predictions next to the completions provided by a language server.
/// Only has an effect if edit prediction provider supports it.
///
/// Default: true
pub show_edit_predictions_in_menu: Option<bool>,
/// Jupyter REPL settings.
pub jupyter: Option<JupyterContent>,
}

View file

@ -551,9 +551,9 @@ impl InlineCompletionButton {
);
}
let is_eager_preview_enabled = match settings.inline_completions_preview_mode() {
language::InlineCompletionPreviewMode::Auto => true,
language::InlineCompletionPreviewMode::WhenHoldingModifier => false,
let is_eager_preview_enabled = match settings.edit_predictions_mode() {
language::EditPredictionsMode::Auto => false,
language::EditPredictionsMode::EagerPreview => true,
};
menu = menu.separator().toggleable_entry(
"Eager Preview",
@ -567,17 +567,17 @@ impl InlineCompletionButton {
fs.clone(),
cx,
move |settings, _cx| {
let inline_preview = match is_eager_preview_enabled {
true => language::InlineCompletionPreviewMode::WhenHoldingModifier,
false => language::InlineCompletionPreviewMode::Auto,
let new_mode = match is_eager_preview_enabled {
true => language::EditPredictionsMode::Auto,
false => language::EditPredictionsMode::EagerPreview,
};
if let Some(edit_predictions) = settings.edit_predictions.as_mut() {
edit_predictions.inline_preview = inline_preview;
edit_predictions.mode = new_mode;
} else {
settings.edit_predictions =
Some(language_settings::EditPredictionSettingsContent {
inline_preview,
mode: new_mode,
..Default::default()
});
}

View file

@ -21,7 +21,7 @@ mod toolchain;
pub mod buffer_tests;
pub mod markdown;
pub use crate::language_settings::InlineCompletionPreviewMode;
pub use crate::language_settings::EditPredictionsMode;
use crate::language_settings::SoftWrap;
use anyhow::{anyhow, Context as _, Result};
use async_trait::async_trait;

View file

@ -227,19 +227,20 @@ pub struct EditPredictionSettings {
/// This list adds to a pre-existing, sensible default set of globs.
/// Any additional ones you add are combined with them.
pub disabled_globs: Vec<GlobMatcher>,
/// When to show edit predictions previews in buffer.
pub inline_preview: InlineCompletionPreviewMode,
/// Configures how edit predictions are displayed in the buffer.
pub mode: EditPredictionsMode,
}
/// The mode in which edit predictions should be displayed.
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InlineCompletionPreviewMode {
/// Display inline when there are no language server completions available.
pub enum EditPredictionsMode {
/// If provider supports it, display inline when holding modifier key (e.g., alt).
/// Otherwise, eager preview is used.
#[default]
Auto,
/// Display inline when holding modifier key (alt by default).
WhenHoldingModifier,
/// Display inline when there are no language server completions available.
EagerPreview,
}
/// The settings for all languages.
@ -434,9 +435,10 @@ pub struct EditPredictionSettingsContent {
/// Any additional ones you add are combined with them.
#[serde(default)]
pub disabled_globs: Option<Vec<String>>,
/// When to show edit predictions previews in buffer.
/// The mode used to display edit predictions in the buffer.
/// Provider support required.
#[serde(default)]
pub inline_preview: InlineCompletionPreviewMode,
pub mode: EditPredictionsMode,
}
/// The settings for enabling/disabling features.
@ -923,8 +925,8 @@ impl AllLanguageSettings {
}
/// Returns the edit predictions preview mode for the given language and path.
pub fn inline_completions_preview_mode(&self) -> InlineCompletionPreviewMode {
self.edit_predictions.inline_preview
pub fn edit_predictions_mode(&self) -> EditPredictionsMode {
self.edit_predictions.mode
}
}
@ -1023,10 +1025,10 @@ impl settings::Settings for AllLanguageSettings {
.features
.as_ref()
.and_then(|f| f.edit_prediction_provider);
let mut inline_completions_preview = default_value
let mut edit_predictions_mode = default_value
.edit_predictions
.as_ref()
.map(|inline_completions| inline_completions.inline_preview)
.map(|edit_predictions| edit_predictions.mode)
.ok_or_else(Self::missing_default)?;
let mut completion_globs: HashSet<&String> = default_value
@ -1060,10 +1062,10 @@ impl settings::Settings for AllLanguageSettings {
edit_prediction_provider = Some(provider);
}
if let Some(inline_completions) = user_settings.edit_predictions.as_ref() {
inline_completions_preview = inline_completions.inline_preview;
if let Some(edit_predictions) = user_settings.edit_predictions.as_ref() {
edit_predictions_mode = edit_predictions.mode;
if let Some(disabled_globs) = inline_completions.disabled_globs.as_ref() {
if let Some(disabled_globs) = edit_predictions.disabled_globs.as_ref() {
completion_globs.extend(disabled_globs.iter());
}
}
@ -1118,7 +1120,7 @@ impl settings::Settings for AllLanguageSettings {
.iter()
.filter_map(|g| Some(globset::Glob::new(g).ok()?.compile_matcher()))
.collect(),
inline_preview: inline_completions_preview,
mode: edit_predictions_mode,
},
defaults,
languages,