Customize language settings JSON schema in language crate
This commit is contained in:
parent
6403bb86e1
commit
d2ba18eae9
4 changed files with 77 additions and 48 deletions
|
@ -10,7 +10,7 @@ use gpui::{
|
|||
};
|
||||
use schemars::{
|
||||
gen::SchemaGenerator,
|
||||
schema::{InstanceType, ObjectValidation, Schema, SchemaObject, SingleOrVec},
|
||||
schema::{InstanceType, Schema, SchemaObject},
|
||||
JsonSchema,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -80,7 +80,7 @@ impl Setting for Settings {
|
|||
|
||||
// Create a schema for a theme name.
|
||||
let theme_name_schema = SchemaObject {
|
||||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))),
|
||||
instance_type: Some(InstanceType::String.into()),
|
||||
enum_values: Some(
|
||||
params
|
||||
.theme_names
|
||||
|
@ -92,51 +92,20 @@ impl Setting for Settings {
|
|||
..Default::default()
|
||||
};
|
||||
|
||||
// Create a schema for a 'languages overrides' object, associating editor
|
||||
// settings with specific langauges.
|
||||
assert!(root_schema.definitions.contains_key("EditorSettings"));
|
||||
root_schema
|
||||
.definitions
|
||||
.extend([("ThemeName".into(), theme_name_schema.into())]);
|
||||
|
||||
let languages_object_schema = SchemaObject {
|
||||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::Object))),
|
||||
object: Some(Box::new(ObjectValidation {
|
||||
properties: params
|
||||
.language_names
|
||||
.iter()
|
||||
.map(|name| {
|
||||
(
|
||||
name.clone(),
|
||||
Schema::new_ref("#/definitions/EditorSettings".into()),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
..Default::default()
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Add these new schemas as definitions, and modify properties of the root
|
||||
// schema to reference them.
|
||||
root_schema.definitions.extend([
|
||||
("ThemeName".into(), theme_name_schema.into()),
|
||||
("Languages".into(), languages_object_schema.into()),
|
||||
]);
|
||||
let root_schema_object = &mut root_schema.schema.object.as_mut().unwrap();
|
||||
|
||||
root_schema_object.properties.extend([
|
||||
(
|
||||
root_schema
|
||||
.schema
|
||||
.object
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.properties
|
||||
.extend([(
|
||||
"theme".to_owned(),
|
||||
Schema::new_ref("#/definitions/ThemeName".into()),
|
||||
),
|
||||
(
|
||||
"languages".to_owned(),
|
||||
Schema::new_ref("#/definitions/Languages".into()),
|
||||
),
|
||||
// For backward compatibility
|
||||
(
|
||||
"language_overrides".to_owned(),
|
||||
Schema::new_ref("#/definitions/Languages".into()),
|
||||
),
|
||||
]);
|
||||
)]);
|
||||
|
||||
root_schema
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue