Remove remaining suspicious serde.defaults

Conrad Irwin created

Change summary

crates/editor/src/editor_tests.rs                      |  4 
crates/editor/src/element.rs                           |  4 
crates/language/src/language.rs                        |  2 
crates/language/src/language_settings.rs               | 99 ++++++++++-
crates/multi_buffer/src/multi_buffer.rs                | 10 
crates/settings/src/settings_content/language.rs       | 41 +---
crates/settings/src/settings_content/language_model.rs |  5 
7 files changed, 105 insertions(+), 60 deletions(-)

Detailed changes

crates/editor/src/editor_tests.rs 🔗

@@ -30,7 +30,7 @@ use language::{
     },
     tree_sitter_python,
 };
-use language_settings::{Formatter, IndentGuideSettings};
+use language_settings::{Formatter, IndentGuideSettingsContent};
 use lsp::CompletionParams;
 use multi_buffer::{IndentGuide, PathKey};
 use parking_lot::Mutex;
@@ -19961,7 +19961,7 @@ fn indent_guide(buffer_id: BufferId, start_row: u32, end_row: u32, depth: u32) -
         end_row: MultiBufferRow(end_row),
         depth,
         tab_size: 4,
-        settings: IndentGuideSettings {
+        settings: IndentGuideSettingsContent {
             enabled: true,
             line_width: 1,
             active_line_width: 1,

crates/editor/src/element.rs 🔗

@@ -51,7 +51,7 @@ use gpui::{
     transparent_black,
 };
 use itertools::Itertools;
-use language::language_settings::{IndentGuideSettings, ShowWhitespaceSetting};
+use language::language_settings::{IndentGuideSettingsContent, ShowWhitespaceSetting};
 use markdown::Markdown;
 use multi_buffer::{
     Anchor, ExcerptId, ExcerptInfo, ExpandExcerptDirection, ExpandInfo, MultiBufferPoint,
@@ -10177,7 +10177,7 @@ pub struct IndentGuideLayout {
     single_indent_width: Pixels,
     depth: u32,
     active: bool,
-    settings: IndentGuideSettings,
+    settings: IndentGuideSettingsContent,
 }
 
 pub struct CursorLayout {

crates/language/src/language.rs 🔗

@@ -22,8 +22,8 @@ mod toolchain;
 #[cfg(test)]
 pub mod buffer_tests;
 
-pub use crate::language_settings::EditPredictionsMode;
 use crate::language_settings::SoftWrap;
+pub use crate::language_settings::{EditPredictionsMode, IndentGuideSettings};
 use anyhow::{Context as _, Result};
 use async_trait::async_trait;
 use collections::{HashMap, HashSet, IndexSet};

crates/language/src/language_settings.rs 🔗

@@ -13,13 +13,13 @@ use schemars::json_schema;
 
 pub use settings::{
     CompletionSettingsContent, EditPredictionProvider, EditPredictionsMode, FormatOnSave,
-    Formatter, FormatterList, IndentGuideSettings, InlayHintKind, LanguageSettingsContent,
+    Formatter, FormatterList, IndentGuideSettingsContent, InlayHintKind, LanguageSettingsContent,
     LspInsertMode, RewrapBehavior, SelectedFormatter, ShowWhitespaceSetting, SoftWrap,
     WordsCompletionMode,
 };
 use settings::{
-    ParameterizedJsonSchema, PrettierSettingsContent, Settings, SettingsContent, SettingsLocation,
-    SettingsStore, SettingsUi,
+    LanguageTaskSettingsContent, ParameterizedJsonSchema, PrettierSettingsContent, Settings,
+    SettingsContent, SettingsLocation, SettingsStore, SettingsUi,
 };
 use shellexpand;
 use std::{borrow::Cow, num::NonZeroU32, path::Path, sync::Arc};
@@ -150,7 +150,7 @@ pub struct LanguageSettings {
     /// Whether to perform linked edits
     pub linked_edits: bool,
     /// Task configuration for this language.
-    pub tasks: settings::LanguageTaskConfig,
+    pub tasks: LanguageTaskSettings,
     /// Whether to pop the completions menu while typing in an editor without
     /// explicitly requesting it.
     pub show_completions_on_input: bool,
@@ -202,6 +202,70 @@ impl CompletionSettings {
     }
 }
 
+/// The settings for indent guides.
+#[derive(Debug, Clone, PartialEq)]
+pub struct IndentGuideSettings {
+    /// Whether to display indent guides in the editor.
+    ///
+    /// Default: true
+    pub enabled: bool,
+    /// The width of the indent guides in pixels, between 1 and 10.
+    ///
+    /// Default: 1
+    pub line_width: u32,
+    /// The width of the active indent guide in pixels, between 1 and 10.
+    ///
+    /// Default: 1
+    pub active_line_width: u32,
+    /// Determines how indent guides are colored.
+    ///
+    /// Default: Fixed
+    pub coloring: settings::IndentGuideColoring,
+    /// Determines how indent guide backgrounds are colored.
+    ///
+    /// Default: Disabled
+    pub background_coloring: settings::IndentGuideBackgroundColoring,
+}
+
+impl IndentGuideSettings {
+    pub fn merge_from(&mut self, src: &Option<IndentGuideSettingsContent>) {
+        let Some(src) = src else { return };
+
+        self.enabled.merge_from(&src.enabled);
+        self.line_width.merge_from(&src.line_width);
+        self.active_line_width.merge_from(&src.active_line_width);
+        self.coloring.merge_from(&src.coloring);
+        self.background_coloring
+            .merge_from(&src.background_coloring);
+    }
+}
+
+#[derive(Debug, Clone)]
+pub struct LanguageTaskSettings {
+    /// Extra task variables to set for a particular language.
+    pub variables: HashMap<String, String>,
+    pub enabled: bool,
+    /// Use LSP tasks over Zed language extension ones.
+    /// If no LSP tasks are returned due to error/timeout or regular execution,
+    /// Zed language extension tasks will be used instead.
+    ///
+    /// Other Zed tasks will still be shown:
+    /// * Zed task from either of the task config file
+    /// * Zed task from history (e.g. one-off task was spawned before)
+    pub prefer_lsp: bool,
+}
+
+impl LanguageTaskSettings {
+    pub fn merge_from(&mut self, src: &Option<LanguageTaskSettingsContent>) {
+        let Some(src) = src.clone() else {
+            return;
+        };
+        self.variables.extend(src.variables);
+        self.enabled.merge_from(&src.enabled);
+        self.prefer_lsp.merge_from(&src.prefer_lsp);
+    }
+}
+
 /// Allows to enable/disable formatting with Prettier
 /// and configure default Prettier, used when no project-level Prettier installation is found.
 /// Prettier formatting is disabled by default.
@@ -517,6 +581,8 @@ impl settings::Settings for AllLanguageSettings {
         let inlay_hints = defaults.inlay_hints.unwrap();
         let completions = defaults.completions.unwrap();
         let prettier = defaults.prettier.unwrap();
+        let indent_guides = defaults.indent_guides.unwrap();
+        let tasks = defaults.tasks.unwrap();
 
         let default_language_settings = LanguageSettings {
             tab_size: defaults.tab_size.unwrap(),
@@ -525,7 +591,13 @@ impl settings::Settings for AllLanguageSettings {
             preferred_line_length: defaults.preferred_line_length.unwrap(),
             show_wrap_guides: defaults.show_wrap_guides.unwrap(),
             wrap_guides: defaults.wrap_guides.unwrap(),
-            indent_guides: defaults.indent_guides.unwrap(),
+            indent_guides: IndentGuideSettings {
+                enabled: indent_guides.enabled.unwrap(),
+                line_width: indent_guides.line_width.unwrap(),
+                active_line_width: indent_guides.active_line_width.unwrap(),
+                coloring: indent_guides.coloring.unwrap(),
+                background_coloring: indent_guides.background_coloring.unwrap(),
+            },
             format_on_save: defaults.format_on_save.unwrap(),
             remove_trailing_whitespace_on_save: defaults
                 .remove_trailing_whitespace_on_save
@@ -568,7 +640,11 @@ impl settings::Settings for AllLanguageSettings {
                 .unwrap(),
             code_actions_on_format: defaults.code_actions_on_format.unwrap(),
             linked_edits: defaults.linked_edits.unwrap(),
-            tasks: defaults.tasks.unwrap(),
+            tasks: LanguageTaskSettings {
+                variables: tasks.variables,
+                enabled: tasks.enabled.unwrap(),
+                prefer_lsp: tasks.prefer_lsp.unwrap(),
+            },
             show_completions_on_input: defaults.show_completions_on_input.unwrap(),
             show_completion_documentation: defaults.show_completion_documentation.unwrap(),
             completions: CompletionSettings {
@@ -787,14 +863,7 @@ impl settings::Settings for AllLanguageSettings {
             d.wrap_guides = arr;
         }
         if let Some(b) = vscode.read_bool("editor.guides.indentation") {
-            if let Some(guide_settings) = d.indent_guides.as_mut() {
-                guide_settings.enabled = b;
-            } else {
-                d.indent_guides = Some(IndentGuideSettings {
-                    enabled: b,
-                    ..Default::default()
-                });
-            }
+            d.indent_guides.get_or_insert_default().enabled = Some(b);
         }
 
         if let Some(b) = vscode.read_bool("editor.guides.formatOnSave") {
@@ -918,7 +987,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
         .code_actions_on_format
         .merge_from(&src.code_actions_on_format.clone());
     settings.linked_edits.merge_from(&src.linked_edits);
-    settings.tasks.merge_from(&src.tasks.clone());
+    settings.tasks.merge_from(&src.tasks);
 
     settings
         .preferred_line_length

crates/multi_buffer/src/multi_buffer.rs 🔗

@@ -17,11 +17,11 @@ use gpui::{App, AppContext as _, Context, Entity, EntityId, EventEmitter, Task};
 use itertools::Itertools;
 use language::{
     AutoindentMode, Buffer, BufferChunks, BufferRow, BufferSnapshot, Capability, CharClassifier,
-    CharKind, Chunk, CursorShape, DiagnosticEntry, DiskState, File, IndentSize, Language,
-    LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point, PointUtf16, Selection,
-    TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId, TreeSitterOptions,
-    Unclipped,
-    language_settings::{IndentGuideSettings, LanguageSettings, language_settings},
+    CharKind, Chunk, CursorShape, DiagnosticEntry, DiskState, File, IndentGuideSettings,
+    IndentSize, Language, LanguageScope, OffsetRangeExt, OffsetUtf16, Outline, OutlineItem, Point,
+    PointUtf16, Selection, TextDimension, TextObject, ToOffset as _, ToPoint as _, TransactionId,
+    TreeSitterOptions, Unclipped,
+    language_settings::{LanguageSettings, language_settings},
 };
 
 use rope::DimensionPair;

crates/settings/src/settings_content/language.rs 🔗

@@ -154,7 +154,7 @@ pub struct LanguageSettingsContent {
     /// Default: []
     pub wrap_guides: Option<Vec<usize>>,
     /// Indent guide related settings.
-    pub indent_guides: Option<IndentGuideSettings>,
+    pub indent_guides: Option<IndentGuideSettingsContent>,
     /// Whether or not to perform a buffer format before saving.
     ///
     /// Default: on
@@ -269,7 +269,7 @@ pub struct LanguageSettingsContent {
     /// Task configuration for this language.
     ///
     /// Default: {}
-    pub tasks: Option<LanguageTaskConfig>,
+    pub tasks: Option<LanguageTaskSettingsContent>,
     /// Whether to pop the completions menu while typing in an editor without
     /// explicitly requesting it.
     ///
@@ -757,55 +757,37 @@ pub enum Formatter {
 /// The settings for indent guides.
 #[skip_serializing_none]
 #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
-pub struct IndentGuideSettings {
+pub struct IndentGuideSettingsContent {
     /// Whether to display indent guides in the editor.
     ///
     /// Default: true
-    #[serde(default = "default_true")]
-    pub enabled: bool,
+    pub enabled: Option<bool>,
     /// The width of the indent guides in pixels, between 1 and 10.
     ///
     /// Default: 1
-    #[serde(default = "line_width")]
-    pub line_width: u32,
+    pub line_width: Option<u32>,
     /// The width of the active indent guide in pixels, between 1 and 10.
     ///
     /// Default: 1
-    #[serde(default = "active_line_width")]
-    pub active_line_width: u32,
+    pub active_line_width: Option<u32>,
     /// Determines how indent guides are colored.
     ///
     /// Default: Fixed
-    #[serde(default)]
-    pub coloring: IndentGuideColoring,
+    pub coloring: Option<IndentGuideColoring>,
     /// Determines how indent guide backgrounds are colored.
     ///
     /// Default: Disabled
-    #[serde(default)]
-    pub background_coloring: IndentGuideBackgroundColoring,
-}
-
-fn default_true() -> bool {
-    true
-}
-
-fn line_width() -> u32 {
-    1
-}
-
-fn active_line_width() -> u32 {
-    line_width()
+    pub background_coloring: Option<IndentGuideBackgroundColoring>,
 }
 
 /// The task settings for a particular language.
 #[skip_serializing_none]
 #[derive(Debug, Clone, Deserialize, PartialEq, Serialize, JsonSchema)]
-pub struct LanguageTaskConfig {
+pub struct LanguageTaskSettingsContent {
     /// Extra task variables to set for a particular language.
     #[serde(default)]
     pub variables: HashMap<String, String>,
-    #[serde(default = "default_true")]
-    pub enabled: bool,
+    pub enabled: Option<bool>,
     /// Use LSP tasks over Zed language extension ones.
     /// If no LSP tasks are returned due to error/timeout or regular execution,
     /// Zed language extension tasks will be used instead.
@@ -813,8 +795,7 @@ pub struct LanguageTaskConfig {
     /// Other Zed tasks will still be shown:
     /// * Zed task from either of the task config file
     /// * Zed task from history (e.g. one-off task was spawned before)
-    #[serde(default = "default_true")]
-    pub prefer_lsp: bool,
+    pub prefer_lsp: Option<bool>,
 }
 
 /// Map from language name to settings. Its `ParameterizedJsonSchema` allows only known language

crates/settings/src/settings_content/language_model.rs 🔗

@@ -368,7 +368,6 @@ pub struct OpenRouterAvailableModel {
 #[skip_serializing_none]
 #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
 pub struct OpenRouterProvider {
-    #[serde(skip_serializing_if = "Option::is_none")]
     order: Option<Vec<String>>,
     #[serde(default = "default_true")]
     allow_fallbacks: bool,
@@ -376,13 +375,9 @@ pub struct OpenRouterProvider {
     require_parameters: bool,
     #[serde(default)]
     data_collection: DataCollection,
-    #[serde(skip_serializing_if = "Option::is_none")]
     only: Option<Vec<String>>,
-    #[serde(skip_serializing_if = "Option::is_none")]
     ignore: Option<Vec<String>>,
-    #[serde(skip_serializing_if = "Option::is_none")]
     quantizations: Option<Vec<String>>,
-    #[serde(skip_serializing_if = "Option::is_none")]
     sort: Option<String>,
 }