Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `font_style` and `font_weight` to serialized theme representation (#6838)
Marshall Bowers536a4ab87a95
diff --git a/Cargo.lock b/Cargo.lockindex 1f54ef99749..2829247cbda 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -7864,6 +7864,7 @@ dependencies = ["serde","serde_derive","serde_json",+ "serde_repr","settings","story","toml",diff --git a/Cargo.toml b/Cargo.tomlindex e01f24f727f..94a9db8382d 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -117,6 +117,7 @@ schemars = { version = "0.8" }serde = { version = "1.0", features = ["derive", "rc"] }serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }+serde_repr = "0.1"smallvec = { version = "1.6", features = ["union"] }smol = { version = "1.2" }strum = { version = "0.25.0", features = ["derive"] }diff --git a/crates/theme/Cargo.toml b/crates/theme/Cargo.tomlindex 48f57f75b2b..e861f50e8ee 100644--- a/crates/theme/Cargo.toml+++ b/crates/theme/Cargo.toml@@ -32,6 +32,7 @@ schemars = { workspace = true, features = ["indexmap"] }serde.workspace = trueserde_derive.workspace = trueserde_json.workspace = true+serde_repr.workspace = truesettings = { path = "../settings" }story = { path = "../story", optional = true }toml.workspace = truediff --git a/crates/theme/src/schema.rs b/crates/theme/src/schema.rsindex 6b34c2075c7..0a9fdcca4d6 100644--- a/crates/theme/src/schema.rs+++ b/crates/theme/src/schema.rs@@ -2,8 +2,12 @@ use anyhow::Result;use gpui::{HighlightStyle, Hsla};use indexmap::IndexMap;use palette::FromColor;+use schemars::gen::SchemaGenerator;+use schemars::schema::{Schema, SchemaObject};use schemars::JsonSchema;-use serde::{Deserialize, Serialize};+use serde::{Deserialize, Deserializer, Serialize};+use serde_json::Value;+use serde_repr::{Deserialize_repr, Serialize_repr};use crate::{StatusColorsRefinement, ThemeColorsRefinement};@@ -1126,8 +1130,71 @@ impl StatusColorsContent {}}+#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]+#[serde(rename_all = "snake_case")]+pub enum FontStyleContent {+ Normal,+ Italic,+ Oblique,+}++#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]+#[repr(u16)]+pub enum FontWeightContent {+ Thin = 100,+ ExtraLight = 200,+ Light = 300,+ Normal = 400,+ Medium = 500,+ Semibold = 600,+ Bold = 700,+ ExtraBold = 800,+ Black = 900,+}++impl JsonSchema for FontWeightContent {+ fn schema_name() -> String {+ "FontWeightContent".to_owned()+ }++ fn is_referenceable() -> bool {+ false+ }++ fn json_schema(_: &mut SchemaGenerator) -> Schema {+ let mut schema_object = SchemaObject::default();+ schema_object.enum_values = Some(vec![+ 100.into(),+ 200.into(),+ 300.into(),+ 400.into(),+ 500.into(),+ 600.into(),+ 700.into(),+ 800.into(),+ 900.into(),+ ]);+ schema_object.into()+ }+}+#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]#[serde(default)]pub struct HighlightStyleContent {pub color: Option<String>,++ #[serde(deserialize_with = "treat_error_as_none")]+ pub font_style: Option<FontStyleContent>,++ #[serde(deserialize_with = "treat_error_as_none")]+ pub font_weight: Option<FontWeightContent>,+}++fn treat_error_as_none<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>+where+ T: Deserialize<'de>,+ D: Deserializer<'de>,+{+ let value: Value = Deserialize::deserialize(deserializer)?;+ Ok(T::deserialize(value).ok())}