settings ui: Create settings key trait (#37489)

This PR separates out the associated constant `KEY` from the `Settings`
trait into a new trait `SettingsKey`. This allows for the key trait to
be derived using attributes to specify the path so that the new
`SettingsUi` derive macro can use the same attributes to determine top
level settings paths thereby removing the need to duplicate the path in
both `Settings::KEY` and `#[settings_ui(path = "...")]`

Co-authored-by: Ben Kunkle <ben@zed.dev>

Release Notes:

- N/A

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
Anthony Eid
2025-09-04 15:19:02 -04:00
committed by GitHub
co-authored by Ben Kunkle
parent 223fda2fe2
commit 5f03202b5c
44 changed files with 473 additions and 255 deletions
+14 -5
View File
@@ -1,10 +1,10 @@
use std::fmt::{Display, Formatter};
use crate as settings;
use crate::{self as settings};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources, VsCodeSettings};
use settings_ui_macros::SettingsUi;
use settings_ui_macros::{SettingsKey, SettingsUi};
/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
///
@@ -101,16 +101,25 @@ impl BaseKeymap {
}
#[derive(
Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default, SettingsUi,
Copy,
Clone,
Debug,
Serialize,
Deserialize,
JsonSchema,
PartialEq,
Eq,
Default,
SettingsUi,
SettingsKey,
)]
// extracted so that it can be an option, and still work with derive(SettingsUi)
#[settings_key(None)]
pub struct BaseKeymapSetting {
pub base_keymap: Option<BaseKeymap>,
}
impl Settings for BaseKeymap {
const KEY: Option<&'static str> = None;
type FileContent = BaseKeymapSetting;
fn load(