Change summary
crates/languages/src/json.rs | 16 ++++++++++------
crates/theme/src/registry.rs | 5 +++++
2 files changed, 15 insertions(+), 6 deletions(-)
Detailed changes
@@ -157,12 +157,16 @@ impl JsonLspAdapter {
) -> Value {
let keymap_schema = KeymapFile::generate_json_schema_for_registered_actions(cx);
let font_names = &cx.text_system().all_font_names();
- let theme_names = &ThemeRegistry::global(cx).list_names();
- let icon_theme_names = &ThemeRegistry::global(cx)
- .list_icon_themes()
- .into_iter()
- .map(|icon_theme| icon_theme.name)
- .collect::<Vec<SharedString>>();
+ let themes = ThemeRegistry::try_global(cx);
+ let theme_names = &themes.clone().map(|t| t.list_names()).unwrap_or_default();
+ let icon_theme_names = &themes
+ .map(|t| {
+ t.list_icon_themes()
+ .into_iter()
+ .map(|icon_theme| icon_theme.name)
+ .collect::<Vec<SharedString>>()
+ })
+ .unwrap_or_default();
let settings_schema = cx
.global::<SettingsStore>()
.json_schema(&SettingsJsonSchemaParams {
@@ -73,6 +73,11 @@ impl ThemeRegistry {
cx.default_global::<GlobalThemeRegistry>().0.clone()
}
+ /// Returns the global [`ThemeRegistry`] if it exists.
+ pub fn try_global(cx: &mut App) -> Option<Arc<Self>> {
+ cx.try_global::<GlobalThemeRegistry>().map(|t| t.0.clone())
+ }
+
/// Sets the global [`ThemeRegistry`].
pub(crate) fn set_global(assets: Box<dyn AssetSource>, cx: &mut App) {
cx.set_global(GlobalThemeRegistry(Arc::new(ThemeRegistry::new(assets))));