Detailed changes
@@ -339,7 +339,7 @@ pub struct TelemetrySettings {
pub metrics: bool,
}
-#[derive(Clone, Serialize, Deserialize, JsonSchema)]
+#[derive(Default, Clone, Serialize, Deserialize, JsonSchema)]
pub struct TelemetrySettingsContent {
pub diagnostics: Option<bool>,
pub metrics: Option<bool>,
@@ -10,17 +10,16 @@ pub struct EditorSettings {
pub show_scrollbars: ShowScrollbars,
}
-#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
+#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ShowScrollbars {
- #[default]
Auto,
System,
Always,
Never,
}
-#[derive(Clone, Serialize, Deserialize, JsonSchema)]
+#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct EditorSettingsContent {
pub cursor_blink: Option<bool>,
pub hover_popover_enabled: Option<bool>,
@@ -49,7 +49,7 @@ pub struct CopilotSettings {
pub disabled_globs: Vec<GlobMatcher>,
}
-#[derive(Clone, Serialize, Deserialize, JsonSchema)]
+#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct AllLanguageSettingsContent {
#[serde(default)]
pub features: Option<FeaturesContent>,
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use settings::Setting;
use std::sync::Arc;
-#[derive(Clone, Serialize, Deserialize, JsonSchema)]
+#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct ProjectSettings {
#[serde(default)]
pub lsp: HashMap<Arc<str>, LspSettings>,
@@ -25,7 +25,7 @@ pub trait Setting: 'static {
const KEY: Option<&'static str>;
/// The type that is stored in an individual JSON file.
- type FileContent: Clone + Serialize + DeserializeOwned + JsonSchema;
+ type FileContent: Clone + Default + Serialize + DeserializeOwned + JsonSchema;
/// The logic for combining together values from one or more JSON files into the
/// final value for this setting.
@@ -460,11 +460,12 @@ impl SettingsStore {
// If the global settings file changed, reload the global value for the field.
if changed_local_path.is_none() {
- setting_value.set_global_value(setting_value.load_setting(
- &default_settings,
- &user_settings_stack,
- cx,
- )?);
+ if let Some(value) = setting_value
+ .load_setting(&default_settings, &user_settings_stack, cx)
+ .log_err()
+ {
+ setting_value.set_global_value(value);
+ }
}
// Reload the local values for the setting.
@@ -495,14 +496,12 @@ impl SettingsStore {
continue;
}
- setting_value.set_local_value(
- path.clone(),
- setting_value.load_setting(
- &default_settings,
- &user_settings_stack,
- cx,
- )?,
- );
+ if let Some(value) = setting_value
+ .load_setting(&default_settings, &user_settings_stack, cx)
+ .log_err()
+ {
+ setting_value.set_local_value(path.clone(), value);
+ }
}
}
}
@@ -536,7 +535,12 @@ impl<T: Setting> AnySettingValue for SettingValue<T> {
fn deserialize_setting(&self, mut json: &serde_json::Value) -> Result<DeserializedSetting> {
if let Some(key) = T::KEY {
- json = json.get(key).unwrap_or(&serde_json::Value::Null);
+ if let Some(value) = json.get(key) {
+ json = value;
+ } else {
+ let value = T::FileContent::default();
+ return Ok(DeserializedSetting(Box::new(value)));
+ }
}
let value = T::FileContent::deserialize(json)?;
Ok(DeserializedSetting(Box::new(value)))
@@ -1126,7 +1130,7 @@ mod tests {
staff: bool,
}
- #[derive(Clone, Serialize, Deserialize, JsonSchema)]
+ #[derive(Default, Clone, Serialize, Deserialize, JsonSchema)]
struct UserSettingsJson {
name: Option<String>,
age: Option<u32>,
@@ -1170,7 +1174,7 @@ mod tests {
key2: String,
}
- #[derive(Clone, Serialize, Deserialize, JsonSchema)]
+ #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
struct MultiKeySettingsJson {
key1: Option<String>,
key2: Option<String>,
@@ -1203,7 +1207,7 @@ mod tests {
Hour24,
}
- #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
+ #[derive(Clone, Default, Debug, Serialize, Deserialize, JsonSchema)]
struct JournalSettingsJson {
pub path: Option<String>,
pub hour_format: Option<HourFormat>,
@@ -1223,7 +1227,7 @@ mod tests {
}
}
- #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
+ #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
struct LanguageSettings {
#[serde(default)]
languages: HashMap<String, LanguageSettingEntry>,
@@ -17,7 +17,7 @@ pub struct WorkspaceSettings {
pub git: GitSettings,
}
-#[derive(Clone, Serialize, Deserialize, JsonSchema)]
+#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
pub struct WorkspaceSettingsContent {
pub active_pane_magnification: Option<f32>,
pub confirm_quit: Option<bool>,