project_settings: Fix default settings values for DiagnosticsSettings (#30686)

Follow-up to #30565

This PR fixes the default settings values for the `DiagnosticsSettings`.
The issue here was that due to the `#[derive(Default)]`, `button` would
be false by default, which unintentionally hid the diagnostics button by
default. The `#[serde(default = `default_true`)]` would only apply iff
the diagnostics key was already present in the user's settings. Thus, if
you have

```json
{
    "diagnostics": {...}
}
```

in your settings, the button would show (given it was not disabled).
However, if the key was not present, the button was not shown: Due to
the derived default for the entire struct, the value would be false.

This PR fixes this by implementing the default instead and moving the
`#[serde(default)]` up to the level of the struct.
I also did the same for the inline diagnostics settings, which already
had a default impl and thus only needed the serde default on the struct
instead of on all the struct fields.

Lastly, I simplified the title bar settings, since the serde attributes
previously had no effect anyway (deserialization happened in the
`TitlebarSettingsContent`, so these attributes had no effect) and we can
remove the `TitlebarSettingsContent` as well as the attributes if we
implement a proper default implementation instead.

Release Notes:

- Fixed the diagnostics status bar button being hidden by default.
This commit is contained in:
Finn Evers 2025-05-14 13:13:51 +02:00 committed by GitHub
parent 775370fd7d
commit 09503333af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 44 deletions

View file

@ -118,22 +118,19 @@ pub enum DirenvSettings {
Direct, Direct,
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct DiagnosticsSettings { pub struct DiagnosticsSettings {
/// Whether to show the project diagnostics button in the status bar. /// Whether to show the project diagnostics button in the status bar.
#[serde(default = "default_true")]
pub button: bool, pub button: bool,
/// Whether or not to include warning diagnostics. /// Whether or not to include warning diagnostics.
#[serde(default = "default_true")]
pub include_warnings: bool, pub include_warnings: bool,
/// Settings for showing inline diagnostics. /// Settings for showing inline diagnostics.
#[serde(default)]
pub inline: InlineDiagnosticsSettings, pub inline: InlineDiagnosticsSettings,
/// Configuration, related to Rust language diagnostics. /// Configuration, related to Rust language diagnostics.
#[serde(default)]
pub cargo: Option<CargoDiagnosticsSettings>, pub cargo: Option<CargoDiagnosticsSettings>,
} }
@ -146,33 +143,29 @@ impl DiagnosticsSettings {
} }
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct InlineDiagnosticsSettings { pub struct InlineDiagnosticsSettings {
/// Whether or not to show inline diagnostics /// Whether or not to show inline diagnostics
/// ///
/// Default: false /// Default: false
#[serde(default)]
pub enabled: bool, pub enabled: bool,
/// Whether to only show the inline diagnostics after a delay after the /// Whether to only show the inline diagnostics after a delay after the
/// last editor event. /// last editor event.
/// ///
/// Default: 150 /// Default: 150
#[serde(default = "default_inline_diagnostics_debounce_ms")]
pub update_debounce_ms: u64, pub update_debounce_ms: u64,
/// The amount of padding between the end of the source line and the start /// The amount of padding between the end of the source line and the start
/// of the inline diagnostic in units of columns. /// of the inline diagnostic in units of columns.
/// ///
/// Default: 4 /// Default: 4
#[serde(default = "default_inline_diagnostics_padding")]
pub padding: u32, pub padding: u32,
/// The minimum column to display inline diagnostics. This setting can be /// The minimum column to display inline diagnostics. This setting can be
/// used to horizontally align inline diagnostics at some position. Lines /// used to horizontally align inline diagnostics at some position. Lines
/// longer than this value will still push diagnostics further to the right. /// longer than this value will still push diagnostics further to the right.
/// ///
/// Default: 0 /// Default: 0
#[serde(default)]
pub min_column: u32, pub min_column: u32,
#[serde(default)]
pub max_severity: Option<DiagnosticSeverity>, pub max_severity: Option<DiagnosticSeverity>,
} }
@ -211,24 +204,27 @@ impl DiagnosticSeverity {
} }
} }
impl Default for InlineDiagnosticsSettings { impl Default for DiagnosticsSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
enabled: false, button: true,
update_debounce_ms: default_inline_diagnostics_debounce_ms(), include_warnings: true,
padding: default_inline_diagnostics_padding(), inline: Default::default(),
min_column: 0, cargo: Default::default(),
max_severity: None,
} }
} }
} }
fn default_inline_diagnostics_debounce_ms() -> u64 { impl Default for InlineDiagnosticsSettings {
150 fn default() -> Self {
} Self {
enabled: false,
fn default_inline_diagnostics_padding() -> u32 { update_debounce_ms: 150,
4 padding: 4,
min_column: 0,
max_severity: None,
}
}
} }
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]

View file

@ -2,50 +2,48 @@ use db::anyhow;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources}; use settings::{Settings, SettingsSources};
use util::serde::default_true;
#[derive(Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Copy, Clone, Serialize, Deserialize, JsonSchema, Debug)]
#[serde(default)]
pub struct TitleBarSettings { pub struct TitleBarSettings {
#[serde(default)]
pub show_branch_icon: bool,
#[serde(default = "default_true")]
pub show_branch_name: bool,
#[serde(default = "default_true")]
pub show_project_items: bool,
#[serde(default = "default_true")]
pub show_onboarding_banner: bool,
#[serde(default = "default_true")]
pub show_user_picture: bool,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
pub struct TitleBarSettingsContent {
/// Whether to show the branch icon beside branch switcher in the title bar. /// Whether to show the branch icon beside branch switcher in the title bar.
/// ///
/// Default: false /// Default: false
pub show_branch_icon: Option<bool>, pub show_branch_icon: bool,
/// Whether to show onboarding banners in the title bar. /// Whether to show onboarding banners in the title bar.
/// ///
/// Default: true /// Default: true
pub show_onboarding_banner: Option<bool>, pub show_onboarding_banner: bool,
/// Whether to show user avatar in the title bar. /// Whether to show user avatar in the title bar.
/// ///
/// Default: true /// Default: true
pub show_user_picture: Option<bool>, pub show_user_picture: bool,
/// Whether to show the branch name button in the titlebar. /// Whether to show the branch name button in the titlebar.
/// ///
/// Default: true /// Default: true
pub show_branch_name: Option<bool>, pub show_branch_name: bool,
/// Whether to show the project host and name in the titlebar. /// Whether to show the project host and name in the titlebar.
/// ///
/// Default: true /// Default: true
pub show_project_items: Option<bool>, pub show_project_items: bool,
}
impl Default for TitleBarSettings {
fn default() -> Self {
Self {
show_branch_icon: false,
show_onboarding_banner: true,
show_user_picture: true,
show_branch_name: true,
show_project_items: true,
}
}
} }
impl Settings for TitleBarSettings { impl Settings for TitleBarSettings {
const KEY: Option<&'static str> = Some("title_bar"); const KEY: Option<&'static str> = Some("title_bar");
type FileContent = TitleBarSettingsContent; type FileContent = Self;
fn load(sources: SettingsSources<Self::FileContent>, _: &mut gpui::App) -> anyhow::Result<Self> fn load(sources: SettingsSources<Self::FileContent>, _: &mut gpui::App) -> anyhow::Result<Self>
where where