Remove old Theme definition (#3195)

This PR removes the old `Theme` definition in favor of the new
`ThemeVariant`s.

The new `SyntaxStyles` have been reverted to the old `SyntaxTheme` that
operates by storing the syntax styles as a vector of
`gpui2::HighlightStyle`s.

This is necessary for the intended usage by `language2`, where we find
the longest key in the theme's syntax styles that matches the capture
name:

18431051d9/crates/language2/src/highlight_map.rs (L15-L41)
This commit is contained in:
Marshall Bowers 2023-11-01 04:05:50 +01:00 committed by GitHub
parent 18431051d9
commit 36a73d657a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 173 additions and 6832 deletions

View file

@ -1,17 +1,22 @@
use crate::{themes, Theme, ThemeMetadata};
use crate::{zed_pro_family, ThemeFamily, ThemeVariant};
use anyhow::{anyhow, Result};
use gpui2::SharedString;
use std::{collections::HashMap, sync::Arc};
pub struct ThemeRegistry {
themes: HashMap<SharedString, Arc<Theme>>,
themes: HashMap<SharedString, Arc<ThemeVariant>>,
}
impl ThemeRegistry {
fn insert_themes(&mut self, themes: impl IntoIterator<Item = Theme>) {
fn insert_theme_families(&mut self, families: impl IntoIterator<Item = ThemeFamily>) {
for family in families.into_iter() {
self.insert_themes(family.themes);
}
}
fn insert_themes(&mut self, themes: impl IntoIterator<Item = ThemeVariant>) {
for theme in themes.into_iter() {
self.themes
.insert(theme.metadata.name.clone(), Arc::new(theme));
self.themes.insert(theme.name.clone(), Arc::new(theme));
}
}
@ -19,11 +24,11 @@ impl ThemeRegistry {
self.themes.keys().cloned()
}
pub fn list(&self, _staff: bool) -> impl Iterator<Item = ThemeMetadata> + '_ {
self.themes.values().map(|theme| theme.metadata.clone())
pub fn list(&self, _staff: bool) -> impl Iterator<Item = SharedString> + '_ {
self.themes.values().map(|theme| theme.name.clone())
}
pub fn get(&self, name: &str) -> Result<Arc<Theme>> {
pub fn get(&self, name: &str) -> Result<Arc<ThemeVariant>> {
self.themes
.get(name)
.ok_or_else(|| anyhow!("theme not found: {}", name))
@ -37,47 +42,7 @@ impl Default for ThemeRegistry {
themes: HashMap::default(),
};
this.insert_themes([
themes::andromeda(),
themes::atelier_cave_dark(),
themes::atelier_cave_light(),
themes::atelier_dune_dark(),
themes::atelier_dune_light(),
themes::atelier_estuary_dark(),
themes::atelier_estuary_light(),
themes::atelier_forest_dark(),
themes::atelier_forest_light(),
themes::atelier_heath_dark(),
themes::atelier_heath_light(),
themes::atelier_lakeside_dark(),
themes::atelier_lakeside_light(),
themes::atelier_plateau_dark(),
themes::atelier_plateau_light(),
themes::atelier_savanna_dark(),
themes::atelier_savanna_light(),
themes::atelier_seaside_dark(),
themes::atelier_seaside_light(),
themes::atelier_sulphurpool_dark(),
themes::atelier_sulphurpool_light(),
themes::ayu_dark(),
themes::ayu_light(),
themes::ayu_mirage(),
themes::gruvbox_dark(),
themes::gruvbox_dark_hard(),
themes::gruvbox_dark_soft(),
themes::gruvbox_light(),
themes::gruvbox_light_hard(),
themes::gruvbox_light_soft(),
themes::one_dark(),
themes::one_light(),
themes::rose_pine(),
themes::rose_pine_dawn(),
themes::rose_pine_moon(),
themes::sandcastle(),
themes::solarized_dark(),
themes::solarized_light(),
themes::summercamp(),
]);
this.insert_theme_families([zed_pro_family()]);
this
}