Settings refactor (#38367)
Co-Authored-By: Ben K <ben@zed.dev> Co-Authored-By: Anthony <anthony@zed.dev> Co-Authored-By: Mikayla <mikayla@zed.dev> Release Notes: - settings: Major internal changes to settings. The primary user-facing effect is that some settings which did not make sense in project settings files are no-longer read from there. (For example the inline blame settings) --------- Co-authored-by: Ben Kunkle <ben@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: Anthony <anthony@zed.dev>
This commit is contained in:
co-authored by
Ben Kunkle
Mikayla Maki
Anthony
parent
0a9023bce0
commit
fcdab160f9
@@ -1,9 +1,14 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use crate::{self as settings};
|
||||
use crate::{
|
||||
self as settings,
|
||||
settings_content::{self, BaseKeymapContent, SettingsContent},
|
||||
};
|
||||
use gpui::App;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsSources, VsCodeSettings};
|
||||
use serde_with::skip_serializing_none;
|
||||
use settings::{Settings, VsCodeSettings};
|
||||
use settings_ui_macros::{SettingsKey, SettingsUi};
|
||||
|
||||
/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
|
||||
@@ -24,6 +29,35 @@ pub enum BaseKeymap {
|
||||
None,
|
||||
}
|
||||
|
||||
impl From<BaseKeymapContent> for BaseKeymap {
|
||||
fn from(value: BaseKeymapContent) -> Self {
|
||||
match value {
|
||||
BaseKeymapContent::VSCode => Self::VSCode,
|
||||
BaseKeymapContent::JetBrains => Self::JetBrains,
|
||||
BaseKeymapContent::SublimeText => Self::SublimeText,
|
||||
BaseKeymapContent::Atom => Self::Atom,
|
||||
BaseKeymapContent::TextMate => Self::TextMate,
|
||||
BaseKeymapContent::Emacs => Self::Emacs,
|
||||
BaseKeymapContent::Cursor => Self::Cursor,
|
||||
BaseKeymapContent::None => Self::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Into<BaseKeymapContent> for BaseKeymap {
|
||||
fn into(self) -> BaseKeymapContent {
|
||||
match self {
|
||||
BaseKeymap::VSCode => BaseKeymapContent::VSCode,
|
||||
BaseKeymap::JetBrains => BaseKeymapContent::JetBrains,
|
||||
BaseKeymap::SublimeText => BaseKeymapContent::SublimeText,
|
||||
BaseKeymap::Atom => BaseKeymapContent::Atom,
|
||||
BaseKeymap::TextMate => BaseKeymapContent::TextMate,
|
||||
BaseKeymap::Emacs => BaseKeymapContent::Emacs,
|
||||
BaseKeymap::Cursor => BaseKeymapContent::Cursor,
|
||||
BaseKeymap::None => BaseKeymapContent::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for BaseKeymap {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
@@ -115,30 +149,23 @@ impl BaseKeymap {
|
||||
)]
|
||||
// extracted so that it can be an option, and still work with derive(SettingsUi)
|
||||
#[settings_key(None)]
|
||||
#[skip_serializing_none]
|
||||
pub struct BaseKeymapSetting {
|
||||
pub base_keymap: Option<BaseKeymap>,
|
||||
}
|
||||
|
||||
impl Settings for BaseKeymap {
|
||||
type FileContent = BaseKeymapSetting;
|
||||
|
||||
fn load(
|
||||
sources: SettingsSources<Self::FileContent>,
|
||||
_: &mut gpui::App,
|
||||
) -> anyhow::Result<Self> {
|
||||
if let Some(Some(user_value)) = sources.user.map(|setting| setting.base_keymap) {
|
||||
return Ok(user_value);
|
||||
}
|
||||
if let Some(Some(server_value)) = sources.server.map(|setting| setting.base_keymap) {
|
||||
return Ok(server_value);
|
||||
}
|
||||
sources
|
||||
.default
|
||||
.base_keymap
|
||||
.ok_or_else(Self::missing_default)
|
||||
fn from_defaults(s: &crate::settings_content::SettingsContent, _cx: &mut App) -> Self {
|
||||
s.base_keymap.unwrap().into()
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &VsCodeSettings, current: &mut Self::FileContent) {
|
||||
current.base_keymap = Some(BaseKeymap::VSCode);
|
||||
fn refine(&mut self, s: &settings_content::SettingsContent, _cx: &mut App) {
|
||||
if let Some(base_keymap) = s.base_keymap {
|
||||
*self = base_keymap.into();
|
||||
};
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &VsCodeSettings, current: &mut SettingsContent) {
|
||||
current.base_keymap = Some(BaseKeymapContent::VSCode);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user