From 4775d839d753350733a3f723b112b40091aad514 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 13 Jul 2022 15:04:03 -0700 Subject: [PATCH] Fix incomplete language names list being used for JSON schema For now, since initializing the languages themselves is still async, create a parallel duplicated code path that is synchronous, and just provided the language names. --- crates/settings/src/settings.rs | 11 ++++++++--- crates/zed/src/languages.rs | 16 ++++++++++++++++ crates/zed/src/zed.rs | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 6073b1ef15..2897b0ab83 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -248,7 +248,7 @@ impl Settings { pub fn settings_file_json_schema( theme_names: Vec, - language_names: Vec, + language_names: &[String], ) -> serde_json::Value { let settings = SchemaSettings::draft07().with(|settings| { settings.option_add_null_type = false; @@ -275,8 +275,13 @@ pub fn settings_file_json_schema( instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))), object: Some(Box::new(ObjectValidation { properties: language_names - .into_iter() - .map(|name| (name, Schema::new_ref("#/definitions/EditorSettings".into()))) + .iter() + .map(|name| { + ( + name.clone(), + Schema::new_ref("#/definitions/EditorSettings".into()), + ) + }) .collect(), ..Default::default() })), diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 82f5701f7f..8dc20bdbd1 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -1,5 +1,6 @@ use gpui::executor::Background; pub use language::*; +use lazy_static::lazy_static; use rust_embed::RustEmbed; use std::{borrow::Cow, str, sync::Arc}; @@ -17,6 +18,21 @@ mod typescript; #[exclude = "*.rs"] struct LanguageDir; +// TODO - Remove this once the `init` function is synchronous again. +lazy_static! { + pub static ref LANGUAGE_NAMES: Vec = LanguageDir::iter() + .filter_map(|path| { + if path.ends_with("config.toml") { + let config = LanguageDir::get(&path)?; + let config = toml::from_slice::(&config.data).ok()?; + Some(config.name.to_string()) + } else { + None + } + }) + .collect(); +} + pub async fn init(languages: Arc, _executor: Arc) { for (name, grammar, lsp_adapter) in [ ( diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index d27a5b7c5b..a033be4dee 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -209,7 +209,7 @@ pub fn initialize_workspace( cx.emit(workspace::Event::PaneAdded(workspace.active_pane().clone())); let theme_names = app_state.themes.list().collect(); - let language_names = app_state.languages.language_names(); + let language_names = &languages::LANGUAGE_NAMES; workspace.project().update(cx, |project, cx| { let action_names = cx.all_action_names().collect::>();