Emit unique highlights for each syntax token
This commit is contained in:
parent
efd1db1b09
commit
60eae3e50a
15 changed files with 1969 additions and 221 deletions
|
@ -28,7 +28,7 @@ struct FamilyMetadata {
|
|||
pub themes: Vec<ThemeMetadata>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ThemeAppearanceJson {
|
||||
Light,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use gpui::{Hsla, Rgba};
|
||||
use serde::Deserialize;
|
||||
|
@ -439,9 +441,34 @@ impl VsCodeThemeConverter {
|
|||
pub fn convert(self) -> Result<UserTheme> {
|
||||
let appearance = self.theme_metadata.appearance.into();
|
||||
|
||||
let status_color_refinements = self.convert_status_colors()?;
|
||||
let theme_colors_refinements = self.convert_theme_colors()?;
|
||||
|
||||
let mut highlight_styles = HashMap::new();
|
||||
|
||||
for token_color in self.theme.token_colors {
|
||||
highlight_styles.extend(token_color.highlight_styles()?);
|
||||
}
|
||||
|
||||
let syntax_theme = UserSyntaxTheme {
|
||||
highlights: highlight_styles.into_iter().collect(),
|
||||
};
|
||||
|
||||
Ok(UserTheme {
|
||||
name: self.theme_metadata.name.into(),
|
||||
appearance,
|
||||
styles: UserThemeStylesRefinement {
|
||||
colors: theme_colors_refinements,
|
||||
status: status_color_refinements,
|
||||
syntax: Some(syntax_theme),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn convert_status_colors(&self) -> Result<StatusColorsRefinement> {
|
||||
let vscode_colors = &self.theme.colors;
|
||||
|
||||
let status_color_refinements = StatusColorsRefinement {
|
||||
Ok(StatusColorsRefinement {
|
||||
// conflict: None,
|
||||
// created: None,
|
||||
deleted: vscode_colors
|
||||
|
@ -466,9 +493,13 @@ impl VsCodeThemeConverter {
|
|||
.as_ref()
|
||||
.traverse(|color| try_parse_color(&color))?,
|
||||
..Default::default()
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
let theme_colors_refinements = ThemeColorsRefinement {
|
||||
fn convert_theme_colors(&self) -> Result<ThemeColorsRefinement> {
|
||||
let vscode_colors = &self.theme.colors;
|
||||
|
||||
Ok(ThemeColorsRefinement {
|
||||
border: vscode_colors
|
||||
.panel_border
|
||||
.as_ref()
|
||||
|
@ -622,26 +653,6 @@ impl VsCodeThemeConverter {
|
|||
.as_ref()
|
||||
.traverse(|color| try_parse_color(&color))?,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut highlight_styles = Vec::new();
|
||||
|
||||
for token_color in self.theme.token_colors {
|
||||
highlight_styles.extend(token_color.highlight_styles()?);
|
||||
}
|
||||
|
||||
let syntax_theme = UserSyntaxTheme {
|
||||
highlights: highlight_styles,
|
||||
};
|
||||
|
||||
Ok(UserTheme {
|
||||
name: self.theme_metadata.name.into(),
|
||||
appearance,
|
||||
styles: UserThemeStylesRefinement {
|
||||
colors: theme_colors_refinements,
|
||||
status: status_color_refinements,
|
||||
syntax: Some(syntax_theme),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
// Map tokenColors style to HighlightStyle (fontStyle, foreground, background)
|
||||
// Take in the scopes from the tokenColors and try to match each to our HighlightStyles
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use serde::Deserialize;
|
||||
use theme::UserHighlightStyle;
|
||||
|
||||
use crate::{util::Traverse, vscode::try_parse_color};
|
||||
use crate::util::Traverse;
|
||||
use crate::vscode::try_parse_color;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
|
@ -30,13 +33,13 @@ pub struct VsCodeTokenColorSettings {
|
|||
}
|
||||
|
||||
impl VsCodeTokenColor {
|
||||
pub fn highlight_styles(&self) -> Result<Vec<(String, UserHighlightStyle)>> {
|
||||
let mut highlight_styles = Vec::new();
|
||||
pub fn highlight_styles(&self) -> Result<HashMap<String, UserHighlightStyle>> {
|
||||
let mut highlight_styles = HashMap::new();
|
||||
|
||||
let scope = match self.scope {
|
||||
Some(VsCodeTokenScope::One(ref scope)) => vec![scope.clone()],
|
||||
Some(VsCodeTokenScope::Many(ref scopes)) => scopes.clone(),
|
||||
None => return Ok(Vec::new()),
|
||||
None => return Ok(HashMap::new()),
|
||||
};
|
||||
|
||||
for scope in &scope {
|
||||
|
@ -56,7 +59,7 @@ impl VsCodeTokenColor {
|
|||
continue;
|
||||
}
|
||||
|
||||
highlight_styles.push((syntax_token, highlight_style));
|
||||
highlight_styles.insert(syntax_token, highlight_style);
|
||||
}
|
||||
|
||||
Ok(highlight_styles)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue