Merge master to colored-indent-guides

pull/6/head
s0LA1337 2 years ago
parent dbd0932921
commit 136487fcde

@ -185,8 +185,8 @@ pub struct Theme {
styles: HashMap<String, Style>,
// tree-sitter highlight styles are stored in a Vec to optimize lookups
scopes: Vec<String>,
highlights: Vec<Style>,
rainbow_length: usize,
highlights: Vec<Style>,
}
impl From<Value> for Theme {
@ -194,11 +194,12 @@ impl From<Value> for Theme {
let values: Result<HashMap<String, Value>> =
toml::from_str(&value.to_string()).context("Failed to load theme");
let (styles, scopes, highlights) = build_theme_values(values);
let (styles, scopes, rainbow_length, highlights) = build_theme_values(values);
Self {
styles,
scopes,
rainbow_length,
highlights,
}
}
@ -266,18 +267,19 @@ impl<'de> Deserialize<'de> for Theme {
Ok(Self {
styles,
scopes,
highlights,
rainbow_length,
highlights,
})
}
}
fn build_theme_values(
values: Result<HashMap<String, Value>>,
) -> (HashMap<String, Style>, Vec<String>, Vec<Style>) {
) -> (HashMap<String, Style>, Vec<String>, usize, Vec<Style>) {
let mut styles = HashMap::new();
let mut scopes = Vec::new();
let mut highlights = Vec::new();
let mut rainbow_length = 0;
if let Ok(mut colors) = values {
// TODO: alert user of parsing failures in editor
@ -295,6 +297,27 @@ fn build_theme_values(
styles.reserve(colors.len());
scopes.reserve(colors.len());
highlights.reserve(colors.len());
for (i, style) in colors
.remove("rainbow")
.and_then(|value| match palette.parse_style_array(value) {
Ok(styles) => Some(styles),
Err(err) => {
warn!("{}", err);
None
}
})
.unwrap_or_else(Theme::default_rainbow)
.iter()
.enumerate()
{
let name = format!("rainbow.{}", i);
styles.insert(name.clone(), *style);
scopes.push(name);
highlights.push(*style);
rainbow_length += 1;
}
for (name, style_value) in colors {
let mut style = Style::default();
if let Err(err) = palette.parse_style(&mut style, style_value) {
@ -308,7 +331,7 @@ fn build_theme_values(
}
}
(styles, scopes, highlights)
(styles, scopes, rainbow_length, highlights)
}
impl Theme {

Loading…
Cancel
Save