Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Publish theme json schema v0.2.0 (#21428)
Peter Tripp41a973b13f4d
diff --git a/assets/themes/andromeda/andromeda.json b/assets/themes/andromeda/andromeda.jsonindex 532d013b369..633b5c308f3 100644--- a/assets/themes/andromeda/andromeda.json+++ b/assets/themes/andromeda/andromeda.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Andromeda","author": "Zed Industries","themes": [diff --git a/assets/themes/atelier/atelier.json b/assets/themes/atelier/atelier.jsonindex 1bf4878b5a4..f72e8e84eed 100644--- a/assets/themes/atelier/atelier.json+++ b/assets/themes/atelier/atelier.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Atelier","author": "Zed Industries","themes": [diff --git a/assets/themes/ayu/ayu.json b/assets/themes/ayu/ayu.jsonindex 00fb6deb913..d511ebf84af 100644--- a/assets/themes/ayu/ayu.json+++ b/assets/themes/ayu/ayu.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Ayu","author": "Zed Industries","themes": [diff --git a/assets/themes/gruvbox/gruvbox.json b/assets/themes/gruvbox/gruvbox.jsonindex a56ea7d0468..908ce3a28a0 100644--- a/assets/themes/gruvbox/gruvbox.json+++ b/assets/themes/gruvbox/gruvbox.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Gruvbox","author": "Zed Industries","themes": [diff --git a/assets/themes/one/one.json b/assets/themes/one/one.jsonindex 0519ead392b..daa09f89950 100644--- a/assets/themes/one/one.json+++ b/assets/themes/one/one.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "One","author": "Zed Industries","themes": [diff --git a/assets/themes/rose_pine/rose_pine.json b/assets/themes/rose_pine/rose_pine.jsonindex 5b66c5ed344..2ff97da1172 100644--- a/assets/themes/rose_pine/rose_pine.json+++ b/assets/themes/rose_pine/rose_pine.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Rosé Pine","author": "Zed Industries","themes": [diff --git a/assets/themes/sandcastle/sandcastle.json b/assets/themes/sandcastle/sandcastle.jsonindex b5239b0a552..ba9e6f50fd2 100644--- a/assets/themes/sandcastle/sandcastle.json+++ b/assets/themes/sandcastle/sandcastle.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Sandcastle","author": "Zed Industries","themes": [diff --git a/assets/themes/solarized/solarized.json b/assets/themes/solarized/solarized.jsonindex 7bd0c53f52c..fe86793cdcc 100644--- a/assets/themes/solarized/solarized.json+++ b/assets/themes/solarized/solarized.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Solarized","author": "Zed Industries","themes": [diff --git a/assets/themes/summercamp/summercamp.json b/assets/themes/summercamp/summercamp.jsonindex 84423a86009..c2206f9aab0 100644--- a/assets/themes/summercamp/summercamp.json+++ b/assets/themes/summercamp/summercamp.json@@ -1,5 +1,5 @@{- "$schema": "https://zed.dev/schema/themes/v0.1.0.json",+ "$schema": "https://zed.dev/schema/themes/v0.2.0.json","name": "Summercamp","author": "Zed Industries","themes": [diff --git a/crates/theme_importer/src/main.rs b/crates/theme_importer/src/main.rsindex d92966ae242..db287956c5d 100644--- a/crates/theme_importer/src/main.rs+++ b/crates/theme_importer/src/main.rs@@ -19,6 +19,8 @@ use theme::{Appearance, AppearanceContent, ThemeFamilyContent};use crate::vscode::VsCodeTheme;use crate::vscode::VsCodeThemeConverter;+const ZED_THEME_SCHEMA_URL: &str = "https://zed.dev/public/schema/themes/v0.2.0.json";+#[derive(Debug, Deserialize)]struct FamilyMetadata {pub name: String,@@ -69,34 +71,53 @@ pub struct ThemeMetadata {#[derive(Parser)]#[command(author, version, about, long_about = None)]struct Args {- /// The path to the theme to import.- theme_path: PathBuf,-- /// Whether to warn when values are missing from the theme.- #[arg(long)]- warn_on_missing: bool,-- /// The path to write the output to.- #[arg(long, short)]- output: Option<PathBuf>,-#[command(subcommand)]- command: Option<Command>,+ command: Command,}-#[derive(Subcommand)]+#[derive(PartialEq, Subcommand)]enum Command {/// Prints the JSON schema for a theme.PrintSchema,+ /// Converts a VSCode theme to Zed format [default]+ Convert {+ /// The path to the theme to import.+ theme_path: PathBuf,++ /// Whether to warn when values are missing from the theme.+ #[arg(long)]+ warn_on_missing: bool,++ /// The path to write the output to.+ #[arg(long, short)]+ output: Option<PathBuf>,+ },}fn main() -> Result<()> {let args = Args::parse();+ match args.command {+ Command::PrintSchema => {+ let theme_family_schema = schema_for!(ThemeFamilyContent);+ println!(+ "{}",+ serde_json::to_string_pretty(&theme_family_schema).unwrap()+ );+ Ok(())+ }+ Command::Convert {+ theme_path,+ warn_on_missing,+ output,+ } => convert(theme_path, output, warn_on_missing),+ }+}++fn convert(theme_file_path: PathBuf, output: Option<PathBuf>, warn_on_missing: bool) -> Result<()> {let log_config = {let mut config = simplelog::ConfigBuilder::new();-- if !args.warn_on_missing {+ if !warn_on_missing {config.add_filter_ignore_str("theme_printer");}@@ -111,28 +132,11 @@ fn main() -> Result<()> {).expect("could not initialize logger");- if let Some(command) = args.command {- match command {- Command::PrintSchema => {- let theme_family_schema = schema_for!(ThemeFamilyContent);-- println!(- "{}",- serde_json::to_string_pretty(&theme_family_schema).unwrap()- );-- return Ok(());- }- }- }-- let theme_file_path = args.theme_path;-let theme_file = match File::open(&theme_file_path) {Ok(file) => file,Err(err) => {log::info!("Failed to open file at path: {:?}", theme_file_path);- return Err(err)?;+ return Err(err.into());}};@@ -148,10 +152,14 @@ fn main() -> Result<()> {let converter = VsCodeThemeConverter::new(vscode_theme, theme_metadata, IndexMap::new());let theme = converter.convert()?;-+ let mut theme = serde_json::to_value(theme).unwrap();+ theme.as_object_mut().unwrap().insert(+ "$schema".to_string(),+ serde_json::Value::String(ZED_THEME_SCHEMA_URL.to_string()),+ );let theme_json = serde_json::to_string_pretty(&theme).unwrap();- if let Some(output) = args.output {+ if let Some(output) = output {let mut file = File::create(output)?;file.write_all(theme_json.as_bytes())?;} else {diff --git a/docs/src/extensions/themes.md b/docs/src/extensions/themes.mdindex 4737a99a3e9..ecdbdace591 100644--- a/docs/src/extensions/themes.md+++ b/docs/src/extensions/themes.md@@ -2,13 +2,13 @@The `themes` directory in an extension should contain one or more theme files.-Each theme file should adhere to the JSON schema specified at [`https://zed.dev/schema/themes/v0.1.0.json`](https://zed.dev/schema/themes/v0.1.0.json).+Each theme file should adhere to the JSON schema specified at [`https://zed.dev/schema/themes/v0.2.0.json`](https://zed.dev/schema/themes/v0.2.0.json).See [this blog post](https://zed.dev/blog/user-themes-now-in-preview) for more details about creating themes.## Theme JSON Structure-The structure of a Zed theme is defined in the [Zed Theme JSON Schema](https://zed.dev/schema/themes/v0.1.0.json).+The structure of a Zed theme is defined in the [Zed Theme JSON Schema](https://zed.dev/schema/themes/v0.2.0.json).A Zed theme consists of a Theme Family object including:diff --git a/script/import-themes b/script/import-themesindex ce9ce9ef12f..8f07df2ef37 100755--- a/script/import-themes+++ b/script/import-themes@@ -1,3 +1,3 @@#!/bin/bash-cargo run -p theme_importer+cargo run -p theme_importer -- "$@"