From 064bdab459b2f118111e11660dce5dbc9aa66c41 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 15 Jun 2024 22:14:39 -0400 Subject: [PATCH] theme: Warn when deprecated `scrollbar_thumb.background` style is used (#13081) This PR adds a warning when the deprecated `scrollbar_thumb.background` style property is present in a theme. This property has been succeeded by `scrollbar.thumb.background`. The primary reason for this is to get it into the `zed-extension` CLI so that we can use it to detect which themes need to be updated. Release Notes: - N/A --- Cargo.lock | 1 + crates/theme/Cargo.toml | 1 + crates/theme/src/registry.rs | 18 ++++++++++++++++-- crates/theme/src/schema.rs | 19 ++++++++++++++----- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8da51b2dad..2dba6b34b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10527,6 +10527,7 @@ dependencies = [ "futures 0.3.28", "gpui", "indexmap 1.9.3", + "log", "palette", "parking_lot", "refineable", diff --git a/crates/theme/Cargo.toml b/crates/theme/Cargo.toml index eaf738439b..934faa1186 100644 --- a/crates/theme/Cargo.toml +++ b/crates/theme/Cargo.toml @@ -25,6 +25,7 @@ fs.workspace = true futures.workspace = true gpui.workspace = true indexmap.workspace = true +log.workspace = true palette = { workspace = true, default-features = false, features = ["std"] } parking_lot.workspace = true refineable.workspace = true diff --git a/crates/theme/src/registry.rs b/crates/theme/src/registry.rs index 6e13df6045..b70377f440 100644 --- a/crates/theme/src/registry.rs +++ b/crates/theme/src/registry.rs @@ -263,9 +263,23 @@ impl ThemeRegistry { pub async fn read_user_theme(theme_path: &Path, fs: Arc) -> Result { let reader = fs.open_sync(theme_path).await?; - let theme = serde_json_lenient::from_reader(reader)?; + let theme_family: ThemeFamilyContent = serde_json_lenient::from_reader(reader)?; - Ok(theme) + for theme in &theme_family.themes { + if theme + .style + .colors + .deprecated_scrollbar_thumb_background + .is_some() + { + log::warn!( + r#"Theme "{theme_name}" is using a deprecated style property: scrollbar_thumb.background. Use `scrollbar.thumb.background` instead."#, + theme_name = theme.name + ) + } + } + + Ok(theme_family) } /// Loads the user theme from the specified path and adds it to the registry. diff --git a/crates/theme/src/schema.rs b/crates/theme/src/schema.rs index e79b80ff44..81a80d3f5b 100644 --- a/crates/theme/src/schema.rs +++ b/crates/theme/src/schema.rs @@ -327,11 +327,15 @@ pub struct ThemeColorsContent { #[serde(rename = "pane_group.border")] pub pane_group_border: Option, + /// The deprecated version of `scrollbar.thumb.background`. + /// + /// Don't use this field. + #[serde(rename = "scrollbar_thumb.background", skip_serializing)] + #[schemars(skip)] + pub deprecated_scrollbar_thumb_background: Option, + /// The color of the scrollbar thumb. - #[serde( - rename = "scrollbar.thumb.background", - alias = "scrollbar_thumb.background" - )] + #[serde(rename = "scrollbar.thumb.background")] pub scrollbar_thumb_background: Option, /// The color of the scrollbar thumb when hovered over. @@ -699,7 +703,12 @@ impl ThemeColorsContent { scrollbar_thumb_background: self .scrollbar_thumb_background .as_ref() - .and_then(|color| try_parse_color(color).ok()), + .and_then(|color| try_parse_color(color).ok()) + .or_else(|| { + self.deprecated_scrollbar_thumb_background + .as_ref() + .and_then(|color| try_parse_color(color).ok()) + }), scrollbar_thumb_hover_background: self .scrollbar_thumb_hover_background .as_ref()