Fix incomplete language names list being used for JSON schema
Max Brunsfeld
created 3 years ago
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.
Change summary
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(-)
Detailed changes
@@ -248,7 +248,7 @@ impl Settings {
pub fn settings_file_json_schema(
theme_names: Vec<String>,
- language_names: Vec<String>,
+ 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()
})),
@@ -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<String> = LanguageDir::iter()
+ .filter_map(|path| {
+ if path.ends_with("config.toml") {
+ let config = LanguageDir::get(&path)?;
+ let config = toml::from_slice::<LanguageConfig>(&config.data).ok()?;
+ Some(config.name.to_string())
+ } else {
+ None
+ }
+ })
+ .collect();
+}
+
pub async fn init(languages: Arc<LanguageRegistry>, _executor: Arc<Background>) {
for (name, grammar, lsp_adapter) in [
(
@@ -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::<Vec<_>>();