diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index ead0b9fb946a..43d4a7a71686 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -4,7 +4,7 @@ use std::{ str, }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, Result}; use helix_core::hashmap; use helix_loader::merge_toml_values; use log::warn; @@ -209,16 +209,18 @@ pub struct Theme { impl From for Theme { fn from(value: Value) -> Self { - let values: Result> = - toml::from_str(&value.to_string()).context("Failed to load theme"); - - let (styles, scopes, highlights) = build_theme_values(values); - - Self { - styles, - scopes, - highlights, - ..Default::default() + if let Value::Table(table) = value { + let (styles, scopes, highlights) = build_theme_values(table); + + Self { + styles, + scopes, + highlights, + ..Default::default() + } + } else { + warn!("Expected theme TOML value to be a table, found {:?}", value); + Default::default() } } } @@ -228,9 +230,9 @@ impl<'de> Deserialize<'de> for Theme { where D: Deserializer<'de>, { - let values = HashMap::::deserialize(deserializer)?; + let values = Map::::deserialize(deserializer)?; - let (styles, scopes, highlights) = build_theme_values(Ok(values)); + let (styles, scopes, highlights) = build_theme_values(values); Ok(Self { styles, @@ -242,39 +244,37 @@ impl<'de> Deserialize<'de> for Theme { } fn build_theme_values( - values: Result>, + mut values: Map, ) -> (HashMap, Vec, Vec