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,10 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
use collections::HashMap;
|
||||
|
||||
use editor::EditorSettings;
|
||||
use gpui::App;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
|
||||
use settings::Settings;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct JupyterSettings {
|
||||
@@ -20,45 +18,20 @@ impl JupyterSettings {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey)]
|
||||
#[settings_key(key = "jupyter")]
|
||||
pub struct JupyterSettingsContent {
|
||||
/// Default kernels to select for each language.
|
||||
///
|
||||
/// Default: `{}`
|
||||
pub kernel_selections: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
impl Default for JupyterSettingsContent {
|
||||
fn default() -> Self {
|
||||
JupyterSettingsContent {
|
||||
kernel_selections: Some(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Settings for JupyterSettings {
|
||||
type FileContent = JupyterSettingsContent;
|
||||
|
||||
fn load(
|
||||
sources: SettingsSources<Self::FileContent>,
|
||||
_cx: &mut gpui::App,
|
||||
) -> anyhow::Result<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let mut settings = JupyterSettings::default();
|
||||
|
||||
for value in sources.defaults_and_customizations() {
|
||||
if let Some(source) = &value.kernel_selections {
|
||||
for (k, v) in source {
|
||||
settings.kernel_selections.insert(k.clone(), v.clone());
|
||||
}
|
||||
}
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let jupyter = content.editor.jupyter.clone().unwrap();
|
||||
Self {
|
||||
kernel_selections: jupyter.kernel_selections.unwrap_or_default(),
|
||||
}
|
||||
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(jupyter) = content.editor.jupyter.as_ref() else {
|
||||
return;
|
||||
};
|
||||
if let Some(kernel_selections) = jupyter.kernel_selections.clone() {
|
||||
self.kernel_selections.extend(kernel_selections)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,38 @@
|
||||
use gpui::App;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
|
||||
use settings::Settings;
|
||||
use util::MergeFrom;
|
||||
|
||||
/// Settings for configuring REPL display and behavior.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, SettingsUi, SettingsKey)]
|
||||
#[settings_key(key = "repl")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ReplSettings {
|
||||
/// Maximum number of lines to keep in REPL's scrollback buffer.
|
||||
/// Clamped with [4, 256] range.
|
||||
///
|
||||
/// Default: 32
|
||||
#[serde(default = "default_max_lines")]
|
||||
pub max_lines: usize,
|
||||
/// Maximum number of columns to keep in REPL's scrollback buffer.
|
||||
/// Clamped with [20, 512] range.
|
||||
///
|
||||
/// Default: 128
|
||||
#[serde(default = "default_max_columns")]
|
||||
pub max_columns: usize,
|
||||
}
|
||||
|
||||
impl Settings for ReplSettings {
|
||||
type FileContent = Self;
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self {
|
||||
let repl = content.repl.as_ref().unwrap();
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _cx: &mut App) -> anyhow::Result<Self> {
|
||||
let mut settings: ReplSettings = sources.json_merge()?;
|
||||
settings.max_columns = settings.max_columns.clamp(20, 512);
|
||||
settings.max_lines = settings.max_lines.clamp(4, 256);
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
|
||||
}
|
||||
|
||||
const DEFAULT_NUM_LINES: usize = 32;
|
||||
const DEFAULT_NUM_COLUMNS: usize = 128;
|
||||
|
||||
fn default_max_lines() -> usize {
|
||||
DEFAULT_NUM_LINES
|
||||
}
|
||||
|
||||
fn default_max_columns() -> usize {
|
||||
DEFAULT_NUM_COLUMNS
|
||||
}
|
||||
|
||||
impl Default for ReplSettings {
|
||||
fn default() -> Self {
|
||||
ReplSettings {
|
||||
max_lines: DEFAULT_NUM_LINES,
|
||||
max_columns: DEFAULT_NUM_COLUMNS,
|
||||
Self {
|
||||
max_lines: repl.max_lines.unwrap(),
|
||||
max_columns: repl.max_columns.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) {
|
||||
let Some(repl) = content.repl.as_ref() else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.max_columns.merge_from(&repl.max_columns);
|
||||
self.max_lines.merge_from(&repl.max_lines);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user