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,
|
||||
};
|
||||
use schemars::{
|
||||
gen::SchemaGenerator,
|
||||
schema::{InstanceType, Schema, SchemaObject},
|
||||
JsonSchema,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct ContainerStyle {
|
||||
#[serde(default)]
|
||||
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 {
|
||||
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)]
|
||||
#[derive(Clone, Copy, Debug, Default, JsonSchema)]
|
||||
pub struct Margin {
|
||||
pub top: 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 top: 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 {
|
||||
#[serde(default, deserialize_with = "deserialize_vec2f")]
|
||||
#[schemars(with = "Vec::<f32>")]
|
||||
offset: Vector2F,
|
||||
#[serde(default)]
|
||||
blur: f32,
|
||||
|
|
|
@ -25,6 +25,7 @@ use anyhow::{anyhow, bail, Result};
|
|||
use async_task::Runnable;
|
||||
pub use event::*;
|
||||
use postage::oneshot;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use sqlez::{
|
||||
bindable::{Bind, Column, StaticColumnCount},
|
||||
|
@ -282,7 +283,7 @@ pub enum PromptLevel {
|
|||
Critical,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Deserialize)]
|
||||
#[derive(Copy, Clone, Debug, Deserialize, JsonSchema)]
|
||||
pub enum CursorStyle {
|
||||
Arrow,
|
||||
ResizeLeftRight,
|
||||
|
|
|
@ -3,9 +3,8 @@ use anyhow::{Context, Result};
|
|||
use collections::BTreeMap;
|
||||
use gpui::{keymap_matcher::Binding, AppContext};
|
||||
use schemars::{
|
||||
gen::SchemaSettings,
|
||||
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation},
|
||||
JsonSchema,
|
||||
gen::{SchemaGenerator, SchemaSettings},
|
||||
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation}, JsonSchema,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{value::RawValue, Value};
|
||||
|
@ -22,10 +21,20 @@ pub struct KeymapBlock {
|
|||
bindings: BTreeMap<String, KeymapAction>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Clone, JsonSchema)]
|
||||
#[derive(Deserialize, Default, Clone)]
|
||||
#[serde(transparent)]
|
||||
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)]
|
||||
struct ActionWithData(Box<str>, Box<RawValue>);
|
||||
|
||||
|
|
|
@ -901,7 +901,7 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, JsonSchema)]
|
||||
pub struct SyntaxTheme {
|
||||
pub highlights: Vec<(String, HighlightStyle)>,
|
||||
}
|
||||
|
|
|
@ -193,10 +193,10 @@ mod tests {
|
|||
fn export_schema() {
|
||||
let theme_settings_content = schema_for!(ThemeSettingsContent);
|
||||
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 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