Add JsonSchema to container style and fix compile errors
This commit is contained in:
parent
ac42522987
commit
193ad64d18
5 changed files with 23 additions and 26 deletions
|
@ -13,14 +13,12 @@ use crate::{
|
||||||
AnyElement, Element, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
AnyElement, Element, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||||
};
|
};
|
||||||
use schemars::{
|
use schemars::{
|
||||||
gen::SchemaGenerator,
|
|
||||||
schema::{InstanceType, Schema, SchemaObject},
|
|
||||||
JsonSchema,
|
JsonSchema,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub struct ContainerStyle {
|
pub struct ContainerStyle {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub margin: Margin,
|
pub margin: Margin,
|
||||||
|
@ -337,20 +335,8 @@ impl ToJson for ContainerStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JsonSchema for ContainerStyle {
|
|
||||||
fn schema_name() -> String {
|
|
||||||
"ContainerStyle".into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
#[derive(Clone, Copy, Debug, Default, JsonSchema)]
|
||||||
let mut schema = SchemaObject::default();
|
|
||||||
schema.instance_type = Some(InstanceType::Integer.into());
|
|
||||||
schema.format = Some("uint".to_owned());
|
|
||||||
Schema::Object(schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
|
||||||
pub struct Margin {
|
pub struct Margin {
|
||||||
pub top: f32,
|
pub top: f32,
|
||||||
pub left: f32,
|
pub left: f32,
|
||||||
|
@ -377,7 +363,7 @@ impl ToJson for Margin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default, JsonSchema)]
|
||||||
pub struct Padding {
|
pub struct Padding {
|
||||||
pub top: f32,
|
pub top: f32,
|
||||||
pub left: f32,
|
pub left: f32,
|
||||||
|
@ -504,9 +490,10 @@ impl ToJson for Padding {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize)]
|
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
||||||
pub struct Shadow {
|
pub struct Shadow {
|
||||||
#[serde(default, deserialize_with = "deserialize_vec2f")]
|
#[serde(default, deserialize_with = "deserialize_vec2f")]
|
||||||
|
#[schemars(with = "Vec::<f32>")]
|
||||||
offset: Vector2F,
|
offset: Vector2F,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
blur: f32,
|
blur: f32,
|
||||||
|
|
|
@ -25,6 +25,7 @@ use anyhow::{anyhow, bail, Result};
|
||||||
use async_task::Runnable;
|
use async_task::Runnable;
|
||||||
pub use event::*;
|
pub use event::*;
|
||||||
use postage::oneshot;
|
use postage::oneshot;
|
||||||
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlez::{
|
use sqlez::{
|
||||||
bindable::{Bind, Column, StaticColumnCount},
|
bindable::{Bind, Column, StaticColumnCount},
|
||||||
|
@ -282,7 +283,7 @@ pub enum PromptLevel {
|
||||||
Critical,
|
Critical,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Deserialize)]
|
#[derive(Copy, Clone, Debug, Deserialize, JsonSchema)]
|
||||||
pub enum CursorStyle {
|
pub enum CursorStyle {
|
||||||
Arrow,
|
Arrow,
|
||||||
ResizeLeftRight,
|
ResizeLeftRight,
|
||||||
|
|
|
@ -3,9 +3,8 @@ use anyhow::{Context, Result};
|
||||||
use collections::BTreeMap;
|
use collections::BTreeMap;
|
||||||
use gpui::{keymap_matcher::Binding, AppContext};
|
use gpui::{keymap_matcher::Binding, AppContext};
|
||||||
use schemars::{
|
use schemars::{
|
||||||
gen::SchemaSettings,
|
gen::{SchemaGenerator, SchemaSettings},
|
||||||
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation},
|
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation}, JsonSchema,
|
||||||
JsonSchema,
|
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::{value::RawValue, Value};
|
use serde_json::{value::RawValue, Value};
|
||||||
|
@ -22,10 +21,20 @@ pub struct KeymapBlock {
|
||||||
bindings: BTreeMap<String, KeymapAction>,
|
bindings: BTreeMap<String, KeymapAction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, Clone, JsonSchema)]
|
#[derive(Deserialize, Default, Clone)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct KeymapAction(Box<RawValue>);
|
pub struct KeymapAction(Box<RawValue>);
|
||||||
|
|
||||||
|
impl JsonSchema for KeymapAction {
|
||||||
|
fn schema_name() -> String {
|
||||||
|
"KeymapAction".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
||||||
|
Schema::Bool(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ActionWithData(Box<str>, Box<RawValue>);
|
struct ActionWithData(Box<str>, Box<RawValue>);
|
||||||
|
|
||||||
|
|
|
@ -901,7 +901,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, JsonSchema)]
|
||||||
pub struct SyntaxTheme {
|
pub struct SyntaxTheme {
|
||||||
pub highlights: Vec<(String, HighlightStyle)>,
|
pub highlights: Vec<(String, HighlightStyle)>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,10 +193,10 @@ mod tests {
|
||||||
fn export_schema() {
|
fn export_schema() {
|
||||||
let theme_settings_content = schema_for!(ThemeSettingsContent);
|
let theme_settings_content = schema_for!(ThemeSettingsContent);
|
||||||
let output1 = serde_json::to_string_pretty(&theme_settings_content).unwrap();
|
let output1 = serde_json::to_string_pretty(&theme_settings_content).unwrap();
|
||||||
std::fs::write("schemas/theme_settings_content.json", output1);
|
std::fs::write("schemas/theme_settings_content.json", output1).ok();
|
||||||
|
|
||||||
let theme_settings = schema_for!(ThemeSettings);
|
let theme_settings = schema_for!(ThemeSettings);
|
||||||
let output2 = serde_json::to_string_pretty(&theme_settings).unwrap();
|
let output2 = serde_json::to_string_pretty(&theme_settings).unwrap();
|
||||||
std::fs::write("schemas/theme_settings.json", output2);
|
std::fs::write("schemas/theme_settings.json", output2).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue