Factor out construction of font-related JSON schemas (#15341)
This PR factors out the construction of the font-related JSON schemas, as they were used in multiple places. Release Notes: - N/A
This commit is contained in:
parent
1ffb34c5fc
commit
b8982ad385
7 changed files with 44 additions and 72 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -10814,7 +10814,6 @@ dependencies = [
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
|
||||||
"settings",
|
"settings",
|
||||||
"smol",
|
"smol",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
|
|
|
@ -1,4 +1,39 @@
|
||||||
use schemars::schema::{RootSchema, Schema};
|
use schemars::schema::{ArrayValidation, InstanceType, RootSchema, Schema, SchemaObject};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
pub struct SettingsJsonSchemaParams<'a> {
|
||||||
|
pub staff_mode: bool,
|
||||||
|
pub language_names: &'a [String],
|
||||||
|
pub font_names: &'a [String],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> SettingsJsonSchemaParams<'a> {
|
||||||
|
pub fn font_family_schema(&self) -> Schema {
|
||||||
|
let available_fonts: Vec<_> = self.font_names.iter().cloned().map(Value::String).collect();
|
||||||
|
|
||||||
|
SchemaObject {
|
||||||
|
instance_type: Some(InstanceType::String.into()),
|
||||||
|
enum_values: Some(available_fonts),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn font_fallback_schema(&self) -> Schema {
|
||||||
|
SchemaObject {
|
||||||
|
instance_type: Some(InstanceType::Array.into()),
|
||||||
|
array: Some(Box::new(ArrayValidation {
|
||||||
|
items: Some(schemars::schema::SingleOrVec::Single(Box::new(
|
||||||
|
self.font_family_schema(),
|
||||||
|
))),
|
||||||
|
unique_items: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
})),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type PropertyName<'a> = &'a str;
|
type PropertyName<'a> = &'a str;
|
||||||
type ReferencePath<'a> = &'a str;
|
type ReferencePath<'a> = &'a str;
|
||||||
|
|
|
@ -13,9 +13,7 @@ pub use editable_setting_control::*;
|
||||||
pub use json_schema::*;
|
pub use json_schema::*;
|
||||||
pub use keymap_file::KeymapFile;
|
pub use keymap_file::KeymapFile;
|
||||||
pub use settings_file::*;
|
pub use settings_file::*;
|
||||||
pub use settings_store::{
|
pub use settings_store::{Settings, SettingsLocation, SettingsSources, SettingsStore};
|
||||||
Settings, SettingsJsonSchemaParams, SettingsLocation, SettingsSources, SettingsStore,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(RustEmbed)]
|
#[derive(RustEmbed)]
|
||||||
#[folder = "../../assets"]
|
#[folder = "../../assets"]
|
||||||
|
|
|
@ -17,6 +17,8 @@ use std::{
|
||||||
};
|
};
|
||||||
use util::{merge_non_null_json_value_into, RangeExt, ResultExt as _};
|
use util::{merge_non_null_json_value_into, RangeExt, ResultExt as _};
|
||||||
|
|
||||||
|
use crate::SettingsJsonSchemaParams;
|
||||||
|
|
||||||
/// A value that can be defined as a user setting.
|
/// A value that can be defined as a user setting.
|
||||||
///
|
///
|
||||||
/// Settings can be loaded from a combination of multiple JSON files.
|
/// Settings can be loaded from a combination of multiple JSON files.
|
||||||
|
@ -146,12 +148,6 @@ pub struct SettingsLocation<'a> {
|
||||||
pub path: &'a Path,
|
pub path: &'a Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SettingsJsonSchemaParams<'a> {
|
|
||||||
pub staff_mode: bool,
|
|
||||||
pub language_names: &'a [String],
|
|
||||||
pub font_names: &'a [String],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A set of strongly-typed setting values defined via multiple JSON files.
|
/// A set of strongly-typed setting values defined via multiple JSON files.
|
||||||
pub struct SettingsStore {
|
pub struct SettingsStore {
|
||||||
setting_values: HashMap<TypeId, Box<dyn AnySettingValue>>,
|
setting_values: HashMap<TypeId, Box<dyn AnySettingValue>>,
|
||||||
|
|
|
@ -12,7 +12,6 @@ workspace = true
|
||||||
path = "src/terminal.rs"
|
path = "src/terminal.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
alacritty_terminal = { git = "https://github.com/alacritty/alacritty", rev = "cacdb5bb3b72bad2c729227537979d95af75978f" }
|
alacritty_terminal = { git = "https://github.com/alacritty/alacritty", rev = "cacdb5bb3b72bad2c729227537979d95af75978f" }
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
@ -25,7 +24,6 @@ release_channel.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
sysinfo.workspace = true
|
sysinfo.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
|
|
|
@ -2,13 +2,8 @@ use collections::HashMap;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
px, AbsoluteLength, AppContext, FontFallbacks, FontFeatures, FontWeight, Pixels, SharedString,
|
px, AbsoluteLength, AppContext, FontFallbacks, FontFeatures, FontWeight, Pixels, SharedString,
|
||||||
};
|
};
|
||||||
use schemars::{
|
use schemars::{gen::SchemaGenerator, schema::RootSchema, JsonSchema};
|
||||||
gen::SchemaGenerator,
|
|
||||||
schema::{ArrayValidation, InstanceType, RootSchema, SchemaObject},
|
|
||||||
JsonSchema,
|
|
||||||
};
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
|
||||||
use settings::{add_references_to_properties, SettingsJsonSchemaParams, SettingsSources};
|
use settings::{add_references_to_properties, SettingsJsonSchemaParams, SettingsSources};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use task::Shell;
|
use task::Shell;
|
||||||
|
@ -202,34 +197,9 @@ impl settings::Settings for TerminalSettings {
|
||||||
_: &AppContext,
|
_: &AppContext,
|
||||||
) -> RootSchema {
|
) -> RootSchema {
|
||||||
let mut root_schema = generator.root_schema_for::<Self::FileContent>();
|
let mut root_schema = generator.root_schema_for::<Self::FileContent>();
|
||||||
let available_fonts: Vec<_> = params
|
|
||||||
.font_names
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.map(Value::String)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let font_family_schema = SchemaObject {
|
|
||||||
instance_type: Some(InstanceType::String.into()),
|
|
||||||
enum_values: Some(available_fonts),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let font_fallback_schema = SchemaObject {
|
|
||||||
instance_type: Some(InstanceType::Array.into()),
|
|
||||||
array: Some(Box::new(ArrayValidation {
|
|
||||||
items: Some(schemars::schema::SingleOrVec::Single(Box::new(
|
|
||||||
font_family_schema.clone().into(),
|
|
||||||
))),
|
|
||||||
unique_items: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
})),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
root_schema.definitions.extend([
|
root_schema.definitions.extend([
|
||||||
("FontFamilies".into(), font_family_schema.into()),
|
("FontFamilies".into(), params.font_family_schema()),
|
||||||
("FontFallbacks".into(), font_fallback_schema.into()),
|
("FontFallbacks".into(), params.font_fallback_schema()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
add_references_to_properties(
|
add_references_to_properties(
|
||||||
|
|
|
@ -7,7 +7,6 @@ use gpui::{
|
||||||
Subscription, ViewContext, WindowContext,
|
Subscription, ViewContext, WindowContext,
|
||||||
};
|
};
|
||||||
use refineable::Refineable;
|
use refineable::Refineable;
|
||||||
use schemars::schema::ArrayValidation;
|
|
||||||
use schemars::{
|
use schemars::{
|
||||||
gen::SchemaGenerator,
|
gen::SchemaGenerator,
|
||||||
schema::{InstanceType, Schema, SchemaObject},
|
schema::{InstanceType, Schema, SchemaObject},
|
||||||
|
@ -620,33 +619,10 @@ impl settings::Settings for ThemeSettings {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let available_fonts = params
|
|
||||||
.font_names
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.map(Value::String)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let font_family_schema = SchemaObject {
|
|
||||||
instance_type: Some(InstanceType::String.into()),
|
|
||||||
enum_values: Some(available_fonts),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
let font_fallback_schema = SchemaObject {
|
|
||||||
instance_type: Some(InstanceType::Array.into()),
|
|
||||||
array: Some(Box::new(ArrayValidation {
|
|
||||||
items: Some(schemars::schema::SingleOrVec::Single(Box::new(
|
|
||||||
font_family_schema.clone().into(),
|
|
||||||
))),
|
|
||||||
unique_items: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
})),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
root_schema.definitions.extend([
|
root_schema.definitions.extend([
|
||||||
("ThemeName".into(), theme_name_schema.into()),
|
("ThemeName".into(), theme_name_schema.into()),
|
||||||
("FontFamilies".into(), font_family_schema.into()),
|
("FontFamilies".into(), params.font_family_schema()),
|
||||||
("FontFallbacks".into(), font_fallback_schema.into()),
|
("FontFallbacks".into(), params.font_fallback_schema()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
add_references_to_properties(
|
add_references_to_properties(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue