From 25876161f86604b83a85a7ba5813d07d73c8d1c4 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 7 Nov 2023 18:45:09 +0100 Subject: [PATCH] theme_importer: Format generated themes (#3255) This PR makes the `theme_importer` format the themes that it generates automatically. Release Notes: - N/A --- crates/theme2/src/registry.rs | 7 ++++-- crates/theme2/src/themes/andromeda.rs | 3 +++ crates/theme2/src/themes/ayu.rs | 3 +++ crates/theme2/src/themes/dracula.rs | 3 +++ crates/theme2/src/themes/gruvbox.rs | 3 +++ crates/theme2/src/themes/mod.rs | 5 ++++- crates/theme2/src/themes/night_owl.rs | 3 +++ crates/theme2/src/themes/nord.rs | 3 +++ crates/theme2/src/themes/notctis.rs | 3 +++ crates/theme2/src/themes/palenight.rs | 3 +++ crates/theme2/src/themes/rose_pine.rs | 3 +++ crates/theme2/src/themes/solarized.rs | 3 +++ crates/theme2/src/themes/synthwave_84.rs | 3 +++ crates/theme_importer/src/main.rs | 27 +++++++++++++++++++++++- 14 files changed, 68 insertions(+), 4 deletions(-) diff --git a/crates/theme2/src/registry.rs b/crates/theme2/src/registry.rs index 37055da361..c9ff549c15 100644 --- a/crates/theme2/src/registry.rs +++ b/crates/theme2/src/registry.rs @@ -52,7 +52,10 @@ impl ThemeRegistry { status: StatusColors::default(), git: GitStatusColors::default(), player: PlayerColors::default(), - syntax: SyntaxTheme::default_dark(), + syntax: match user_theme.appearance { + Appearance::Light => SyntaxTheme::default_light(), + Appearance::Dark => SyntaxTheme::default_dark(), + }, }, } })); @@ -81,7 +84,7 @@ impl Default for ThemeRegistry { }; this.insert_theme_families([zed_pro_family()]); - this.insert_user_theme_familes(crate::all_imported_themes()); + this.insert_user_theme_familes(crate::all_user_themes()); this } diff --git a/crates/theme2/src/themes/andromeda.rs b/crates/theme2/src/themes/andromeda.rs index 0d58dc9d56..22a0a8741c 100644 --- a/crates/theme2/src/themes/andromeda.rs +++ b/crates/theme2/src/themes/andromeda.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/ayu.rs b/crates/theme2/src/themes/ayu.rs index 6298de40ee..8d79289046 100644 --- a/crates/theme2/src/themes/ayu.rs +++ b/crates/theme2/src/themes/ayu.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/dracula.rs b/crates/theme2/src/themes/dracula.rs index ea0e185e05..57c04851a5 100644 --- a/crates/theme2/src/themes/dracula.rs +++ b/crates/theme2/src/themes/dracula.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/gruvbox.rs b/crates/theme2/src/themes/gruvbox.rs index d06f53da67..2e79b250da 100644 --- a/crates/theme2/src/themes/gruvbox.rs +++ b/crates/theme2/src/themes/gruvbox.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/mod.rs b/crates/theme2/src/themes/mod.rs index b013a86989..c48338b184 100644 --- a/crates/theme2/src/themes/mod.rs +++ b/crates/theme2/src/themes/mod.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + mod andromeda; mod ayu; mod dracula; @@ -24,7 +27,7 @@ pub use synthwave_84::*; use crate::UserThemeFamily; -pub(crate) fn all_imported_themes() -> Vec { +pub(crate) fn all_user_themes() -> Vec { vec![ rose_pine(), night_owl(), diff --git a/crates/theme2/src/themes/night_owl.rs b/crates/theme2/src/themes/night_owl.rs index 4227c53b7a..90ae45f879 100644 --- a/crates/theme2/src/themes/night_owl.rs +++ b/crates/theme2/src/themes/night_owl.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/nord.rs b/crates/theme2/src/themes/nord.rs index 981b460d10..b1dedd6b16 100644 --- a/crates/theme2/src/themes/nord.rs +++ b/crates/theme2/src/themes/nord.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/notctis.rs b/crates/theme2/src/themes/notctis.rs index d8673824db..f5b8f1207d 100644 --- a/crates/theme2/src/themes/notctis.rs +++ b/crates/theme2/src/themes/notctis.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/palenight.rs b/crates/theme2/src/themes/palenight.rs index 64df5d7ecb..7ed27d3b75 100644 --- a/crates/theme2/src/themes/palenight.rs +++ b/crates/theme2/src/themes/palenight.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/rose_pine.rs b/crates/theme2/src/themes/rose_pine.rs index 6fd641861a..913af127fb 100644 --- a/crates/theme2/src/themes/rose_pine.rs +++ b/crates/theme2/src/themes/rose_pine.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/solarized.rs b/crates/theme2/src/themes/solarized.rs index 1f1c55f081..0a78328e2e 100644 --- a/crates/theme2/src/themes/solarized.rs +++ b/crates/theme2/src/themes/solarized.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme2/src/themes/synthwave_84.rs b/crates/theme2/src/themes/synthwave_84.rs index a512c087ff..8c0520ee11 100644 --- a/crates/theme2/src/themes/synthwave_84.rs +++ b/crates/theme2/src/themes/synthwave_84.rs @@ -1,3 +1,6 @@ +// This file was generated by the `theme_importer`. +// Be careful when modifying it by hand. + use gpui::rgba; use crate::{ diff --git a/crates/theme_importer/src/main.rs b/crates/theme_importer/src/main.rs index e2ece76b12..b41994a0be 100644 --- a/crates/theme_importer/src/main.rs +++ b/crates/theme_importer/src/main.rs @@ -5,6 +5,7 @@ mod vscode; use std::fs::{self, File}; use std::io::Write; use std::path::PathBuf; +use std::process::Command; use std::str::FromStr; use anyhow::{anyhow, Context, Result}; @@ -152,6 +153,9 @@ fn main() -> Result<()> { let theme_module = format!( r#" + // This file was generated by the `theme_importer`. + // Be careful when modifying it by hand. + use gpui::rgba; use crate::{{ @@ -174,7 +178,7 @@ fn main() -> Result<()> { r#" use crate::UserThemeFamily; - pub(crate) fn all_imported_themes() -> Vec {{ + pub(crate) fn all_user_themes() -> Vec {{ vec![{all_themes}] }} "#, @@ -187,6 +191,9 @@ fn main() -> Result<()> { let mod_rs_contents = format!( r#" + // This file was generated by the `theme_importer`. + // Be careful when modifying it by hand. + {mod_statements} {use_statements} @@ -208,5 +215,23 @@ fn main() -> Result<()> { mod_rs_file.write_all(mod_rs_contents.as_bytes())?; + println!("Formatting themes..."); + + let format_result = format_themes_crate() + // We need to format a second time to catch all of the formatting issues. + .and_then(|_| format_themes_crate()); + + if let Err(err) = format_result { + eprintln!("Failed to format themes: {}", err); + } + + println!("Done!"); + Ok(()) } + +fn format_themes_crate() -> std::io::Result { + Command::new("cargo") + .args(["fmt", "--package", "theme2"]) + .output() +}