diff --git a/assets/settings/default.json b/assets/settings/default.json index f10ab796a2..b84dc97485 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -540,8 +540,18 @@ // Controls whether edit predictions are shown immediately (true) // or manually by triggering `editor::ShowEditPrediction` (false). "show_edit_predictions": true, - // Controls whether edit predictions are shown in a given language scope. - // Example: ["string", "comment"] + // Disable edit predictions in these language scopes, such as "comment" and + // "string". + // + // Use `"..."` to add scopes without repeating the inherited list. In project + // settings, it extends the user or parent configuration value. In + // language-specific settings, it extends the scopes inherited by that + // language. Omit `"..."` to replace the inherited list. + // + // Inherited scopes are inserted at `"..."`, and duplicates keep their first + // occurrence. + // + // Set `[]` to clear the inherited list. Omit this setting to inherit it unchanged. "edit_predictions_disabled_in": [], // Whether to show tabs and spaces in the editor. // This setting can take four values: diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index e22b5f9428..3cd3eac021 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -118,8 +118,18 @@ pub struct LanguageSettings { /// Controls whether edit predictions are shown immediately (true) /// or manually by triggering `editor::ShowEditPrediction` (false). pub show_edit_predictions: bool, - /// Controls whether edit predictions are shown in the given language - /// scopes. + /// Disable edit predictions in these language scopes, such as "comment" and + /// "string". + /// + /// Use `"..."` to add scopes without repeating the inherited list. In project + /// settings, it extends the user or parent configuration value. In + /// language-specific settings, it extends the scopes inherited by that + /// language. Omit `"..."` to replace the inherited list. + /// + /// Inherited scopes are inserted at `"..."`, and duplicates keep their first + /// occurrence. + /// + /// Set `[]` to clear the inherited list. Omit this setting to inherit it unchanged. pub edit_predictions_disabled_in: Vec, /// Whether to show tabs and spaces in the editor. pub show_whitespaces: settings::ShowWhitespaceSetting, @@ -861,7 +871,7 @@ impl settings::Settings for AllLanguageSettings { document_symbols: settings.document_symbols.unwrap(), allow_rewrap: settings.allow_rewrap.unwrap(), show_edit_predictions: settings.show_edit_predictions.unwrap(), - edit_predictions_disabled_in: settings.edit_predictions_disabled_in.unwrap(), + edit_predictions_disabled_in: settings.edit_predictions_disabled_in.unwrap().0, show_whitespaces: settings.show_whitespaces.unwrap(), whitespace_map: WhitespaceMap { space: SharedString::new(whitespace_map.space.unwrap().to_string()), @@ -1116,6 +1126,139 @@ mod tests { }); } + #[gpui::test] + fn test_edit_predictions_disabled_in_language_overrides(cx: &mut App) { + let mut store = SettingsStore::new(cx, &settings::default_settings()); + store.register_setting::(); + assert!( + store + .get::(None) + .defaults + .edit_predictions_disabled_in + .is_empty() + ); + + for (language_settings, expected) in [ + (serde_json::json!({}), vec!["comment"]), + ( + serde_json::json!({"edit_predictions_disabled_in": ["string", "..."]}), + vec!["string", "comment"], + ), + ( + serde_json::json!({"edit_predictions_disabled_in": ["string"]}), + vec!["string"], + ), + ( + serde_json::json!({"edit_predictions_disabled_in": []}), + vec![], + ), + ] { + store + .set_user_settings( + &serde_json::json!({ + "edit_predictions_disabled_in": ["comment"], + "languages": {"Rust": language_settings}, + }) + .to_string(), + cx, + ) + .expect("user settings should load"); + let settings = store.get::(None); + assert_eq!(settings.defaults.edit_predictions_disabled_in, ["comment"]); + assert_eq!( + settings + .languages + .get(&LanguageName::from("Rust")) + .expect("Rust settings should load") + .edit_predictions_disabled_in, + expected, + "language settings: {language_settings}" + ); + } + } + + #[gpui::test] + fn test_edit_predictions_disabled_in_project_overrides(cx: &mut App) { + let mut store = SettingsStore::new(cx, &settings::default_settings()); + store.register_setting::(); + let worktree_id = WorktreeId::from_usize(1); + let root = LocalSettingsPath::InWorktree(rel_path("root").into()); + let child = LocalSettingsPath::InWorktree(rel_path("root/child").into()); + + store + .set_user_settings(r#"{"edit_predictions_disabled_in":["comment"]}"#, cx) + .expect("user settings should load"); + store + .set_local_settings( + worktree_id, + root, + LocalSettingsKind::Settings, + Some(r#"{"edit_predictions_disabled_in":["string","..."]}"#), + cx, + ) + .expect("project settings should load"); + + for (overrides, expected) in [ + (serde_json::json!({}), vec!["string", "comment"]), + ( + serde_json::json!({"edit_predictions_disabled_in": ["documentation", "..."]}), + vec!["documentation", "string", "comment"], + ), + ( + serde_json::json!({"edit_predictions_disabled_in": ["documentation"]}), + vec!["documentation"], + ), + ( + serde_json::json!({"edit_predictions_disabled_in": []}), + vec![], + ), + ] { + for language_specific in [false, true] { + let content = if language_specific { + serde_json::json!({"languages": {"Rust": overrides}}) + } else { + overrides.clone() + }; + store + .set_local_settings( + worktree_id, + child.clone(), + LocalSettingsKind::Settings, + Some(&content.to_string()), + cx, + ) + .expect("child settings should load"); + let settings = store.get::(Some(SettingsLocation { + worktree_id, + path: rel_path("root/child/file.rs"), + })); + let resolved = if language_specific { + assert_eq!( + settings.defaults.edit_predictions_disabled_in, + ["string", "comment"] + ); + settings + .languages + .get(&LanguageName::from("Rust")) + .expect("Rust settings should load") + } else { + &settings.defaults + }; + assert_eq!( + resolved.edit_predictions_disabled_in, expected, + "project settings: {content}" + ); + } + } + assert_eq!( + store + .get::(None) + .defaults + .edit_predictions_disabled_in, + ["comment"] + ); + } + #[gpui::test] fn test_edit_predictions_disabled_globs_replace_and_clear(cx: &mut App) { let mut store = SettingsStore::new(cx, &settings::default_settings()); diff --git a/crates/settings_content/src/language.rs b/crates/settings_content/src/language.rs index 7c072a2ab8..75ea59f83d 100644 --- a/crates/settings_content/src/language.rs +++ b/crates/settings_content/src/language.rs @@ -656,13 +656,38 @@ pub struct LanguageSettingsContent { /// /// Default: true pub show_edit_predictions: Option, - /// Controls whether edit predictions are shown in the given language - /// scopes. + /// Disable edit predictions in these language scopes, such as "comment" and + /// "string". /// - /// Example: ["string", "comment"] + /// Default: /// - /// Default: [] - pub edit_predictions_disabled_in: Option>, + /// ```json + /// { + /// "edit_predictions_disabled_in": [] + /// } + /// ``` + /// + /// Use `"..."` to add scopes without repeating the inherited list. In project + /// settings, it extends the user or parent configuration value. In + /// language-specific settings, it extends the scopes inherited by that + /// language. Omit `"..."` to replace the inherited list. + /// + /// ```json + /// { + /// "edit_predictions_disabled_in": ["comment"], + /// "languages": { + /// "Go": { + /// "edit_predictions_disabled_in": ["string", "..."] + /// } + /// } + /// } + /// ``` + /// + /// Inherited scopes are inserted at `"..."`, and duplicates keep their first + /// occurrence. + /// + /// Set `[]` to clear the inherited list. Omit this setting to inherit it unchanged. + pub edit_predictions_disabled_in: Option, /// Whether to show tabs and spaces in the editor. pub show_whitespaces: Option, /// Visible characters used to render whitespace when show_whitespaces is enabled. diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs index da09f0d46a..7080baf2a2 100644 --- a/crates/settings_ui/src/page_data.rs +++ b/crates/settings_ui/src/page_data.rs @@ -11188,7 +11188,7 @@ fn edit_prediction_language_settings_section() -> [SettingsPageItem; 5] { }), SettingsPageItem::SettingItem(SettingItem { title: "Disable in Language Scopes", - description: "Controls whether edit predictions are shown in the given language scopes.", + description: "Disable edit predictions in these language scopes, such as \"comment\" and \"string\". Use \"...\" to add scopes without repeating the inherited list.", field: Box::new( SettingField { organization_override: None, diff --git a/docs/src/reference/all-settings.md b/docs/src/reference/all-settings.md index 12ea64e57f..2096aadeef 100644 --- a/docs/src/reference/all-settings.md +++ b/docs/src/reference/all-settings.md @@ -898,42 +898,33 @@ See [Configuring the Prediction Debounce](../ai/edit-prediction.md#configuring-t ## Edit Predictions Disabled in -- Description: A list of language scopes in which edit predictions should be disabled. - Setting: `edit_predictions_disabled_in` -- Default: `[]` - -**Options** - -List of `string` values - -1. Don't show edit predictions in comments: +- Description: Disable edit predictions in these language scopes, such as "comment" and "string". +- Default: ```json [settings] { - "edit_predictions_disabled_in": ["comment"] + "edit_predictions_disabled_in": [] } ``` -2. Don't show edit predictions in strings and comments: - -```json [settings] -{ - "edit_predictions_disabled_in": ["comment", "string"] -} -``` - -3. Only in Go, don't show edit predictions in strings and comments: +Use `"..."` to add scopes without repeating the inherited list. In project settings, it extends the user or parent configuration value. In language-specific settings, it extends the scopes inherited by that language. Omit `"..."` to replace the inherited list. ```json [settings] { + "edit_predictions_disabled_in": ["comment"], "languages": { "Go": { - "edit_predictions_disabled_in": ["comment", "string"] + "edit_predictions_disabled_in": ["string", "..."] } } } ``` +Inherited scopes are inserted at `"..."`, and duplicates keep their first occurrence. + +Set `[]` to clear the inherited list. Omit this setting to inherit it unchanged. + ## Current Line Highlight - Description: How to highlight the current line in the editor.