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
@@ -4,10 +4,8 @@
|
||||
//! disable Vim/Helix modes without having to depend on the `vim` crate in its
|
||||
//! entirety.
|
||||
|
||||
use anyhow::Result;
|
||||
use gpui::App;
|
||||
use schemars::JsonSchema;
|
||||
use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
|
||||
use settings::{Settings, SettingsContent};
|
||||
|
||||
/// Initializes the `vim_mode_setting` crate.
|
||||
pub fn init(cx: &mut App) {
|
||||
@@ -17,97 +15,34 @@ pub fn init(cx: &mut App) {
|
||||
|
||||
pub struct VimModeSetting(pub bool);
|
||||
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Debug,
|
||||
Default,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
SettingsUi,
|
||||
SettingsKey,
|
||||
JsonSchema,
|
||||
)]
|
||||
#[settings_key(None)]
|
||||
pub struct VimModeSettingContent {
|
||||
/// Whether or not to enable Vim mode.
|
||||
///
|
||||
/// Default: false
|
||||
pub vim_mode: Option<bool>,
|
||||
}
|
||||
|
||||
impl Settings for VimModeSetting {
|
||||
type FileContent = VimModeSettingContent;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
|
||||
Ok(Self(
|
||||
[
|
||||
sources.profile,
|
||||
sources.release_channel,
|
||||
sources.user,
|
||||
sources.server,
|
||||
Some(sources.default),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|mode| mode.vim_mode)
|
||||
.next()
|
||||
.ok_or_else(Self::missing_default)?,
|
||||
))
|
||||
fn from_defaults(content: &SettingsContent, _cx: &mut App) -> Self {
|
||||
Self(content.vim_mode.unwrap())
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {
|
||||
fn refine(&mut self, content: &SettingsContent, _cx: &mut App) {
|
||||
if let Some(vim_mode) = content.vim_mode {
|
||||
self.0 = vim_mode;
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _content: &mut SettingsContent) {
|
||||
// TODO: could possibly check if any of the `vim.<foo>` keys are set?
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HelixModeSetting(pub bool);
|
||||
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Debug,
|
||||
Default,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
SettingsUi,
|
||||
SettingsKey,
|
||||
JsonSchema,
|
||||
)]
|
||||
#[settings_key(None)]
|
||||
pub struct HelixModeSettingContent {
|
||||
/// Whether or not to enable Helix mode.
|
||||
///
|
||||
/// Default: false
|
||||
pub helix_mode: Option<bool>,
|
||||
}
|
||||
|
||||
impl Settings for HelixModeSetting {
|
||||
type FileContent = HelixModeSettingContent;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
|
||||
Ok(Self(
|
||||
[
|
||||
sources.profile,
|
||||
sources.release_channel,
|
||||
sources.user,
|
||||
sources.server,
|
||||
Some(sources.default),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|mode| mode.helix_mode)
|
||||
.next()
|
||||
.ok_or_else(Self::missing_default)?,
|
||||
))
|
||||
fn from_defaults(content: &SettingsContent, _cx: &mut App) -> Self {
|
||||
Self(content.helix_mode.unwrap())
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {
|
||||
// TODO: could possibly check if any of the `helix.<foo>` keys are set?
|
||||
fn refine(&mut self, content: &SettingsContent, _cx: &mut App) {
|
||||
if let Some(helix_mode) = content.helix_mode {
|
||||
self.0 = helix_mode;
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut SettingsContent) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user