Migrate to schemars version 1.0 (#33635)
The major change in schemars 1.0 is that now schemas are represented as plain json values instead of specialized datatypes. This allows for more concise construction and manipulation. This change also improves how settings schemas are generated. Each top level settings type was being generated as a full root schema including the definitions it references, and then these were merged. This meant generating all shared definitions multiple times, and might have bugs in cases where there are two types with the same names. Now instead the schemar generator's `definitions` are built up as they normally are and the `Settings` trait no longer has a special `json_schema` method. To handle types that have schema that vary at runtime (`FontFamilyName`, `ThemeName`, etc), values of `ParameterizedJsonSchema` are collected by `inventory`, and the schema definitions for these types are replaced. To help check that this doesn't break anything, I tried to minimize the overall [schema diff](https://gist.github.com/mgsloan/1de549def20399d6f37943a3c1583ee7) with some patches to make the order more consistent + schemas also sorted with `jq -S .`. A skim of the diff shows that the diffs come from: * `enum: ["value"]` turning into `const: "value"` * Differences in handling of newlines for "description" * Schemas for generic types no longer including the parameter name, now all disambiguation is with numeric suffixes * Enums now using `oneOf` instead of `anyOf`. Release Notes: - N/A
This commit is contained in:
parent
a2e786e0f9
commit
5fafab6e52
42 changed files with 714 additions and 963 deletions
|
@ -2,14 +2,14 @@ use alacritty_terminal::vte::ansi::{
|
|||
CursorShape as AlacCursorShape, CursorStyle as AlacCursorStyle,
|
||||
};
|
||||
use collections::HashMap;
|
||||
use gpui::{
|
||||
AbsoluteLength, App, FontFallbacks, FontFeatures, FontWeight, Pixels, SharedString, px,
|
||||
};
|
||||
use schemars::{JsonSchema, r#gen::SchemaGenerator, schema::RootSchema};
|
||||
use gpui::{AbsoluteLength, App, FontFallbacks, FontFeatures, FontWeight, Pixels, px};
|
||||
use schemars::JsonSchema;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use settings::{SettingsJsonSchemaParams, SettingsSources, add_references_to_properties};
|
||||
|
||||
use settings::SettingsSources;
|
||||
use std::path::PathBuf;
|
||||
use task::Shell;
|
||||
use theme::FontFamilyName;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
@ -29,7 +29,7 @@ pub struct TerminalSettings {
|
|||
pub shell: Shell,
|
||||
pub working_directory: WorkingDirectory,
|
||||
pub font_size: Option<Pixels>,
|
||||
pub font_family: Option<SharedString>,
|
||||
pub font_family: Option<FontFamilyName>,
|
||||
pub font_fallbacks: Option<FontFallbacks>,
|
||||
pub font_features: Option<FontFeatures>,
|
||||
pub font_weight: Option<FontWeight>,
|
||||
|
@ -147,13 +147,14 @@ pub struct TerminalSettingsContent {
|
|||
///
|
||||
/// If this option is not included,
|
||||
/// the terminal will default to matching the buffer's font family.
|
||||
pub font_family: Option<String>,
|
||||
pub font_family: Option<FontFamilyName>,
|
||||
|
||||
/// Sets the terminal's font fallbacks.
|
||||
///
|
||||
/// If this option is not included,
|
||||
/// the terminal will default to matching the buffer's font fallbacks.
|
||||
pub font_fallbacks: Option<Vec<String>>,
|
||||
#[schemars(extend("uniqueItems" = true))]
|
||||
pub font_fallbacks: Option<Vec<FontFamilyName>>,
|
||||
|
||||
/// Sets the terminal's line height.
|
||||
///
|
||||
|
@ -234,33 +235,13 @@ impl settings::Settings for TerminalSettings {
|
|||
sources.json_merge()
|
||||
}
|
||||
|
||||
fn json_schema(
|
||||
generator: &mut SchemaGenerator,
|
||||
params: &SettingsJsonSchemaParams,
|
||||
_: &App,
|
||||
) -> RootSchema {
|
||||
let mut root_schema = generator.root_schema_for::<Self::FileContent>();
|
||||
root_schema.definitions.extend([
|
||||
("FontFamilies".into(), params.font_family_schema()),
|
||||
("FontFallbacks".into(), params.font_fallback_schema()),
|
||||
]);
|
||||
|
||||
add_references_to_properties(
|
||||
&mut root_schema,
|
||||
&[
|
||||
("font_family", "#/definitions/FontFamilies"),
|
||||
("font_fallbacks", "#/definitions/FontFallbacks"),
|
||||
],
|
||||
);
|
||||
|
||||
root_schema
|
||||
}
|
||||
|
||||
fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
|
||||
let name = |s| format!("terminal.integrated.{s}");
|
||||
|
||||
vscode.f32_setting(&name("fontSize"), &mut current.font_size);
|
||||
vscode.string_setting(&name("fontFamily"), &mut current.font_family);
|
||||
if let Some(font_family) = vscode.read_string(&name("fontFamily")) {
|
||||
current.font_family = Some(FontFamilyName(font_family.into()));
|
||||
}
|
||||
vscode.bool_setting(&name("copyOnSelection"), &mut current.copy_on_select);
|
||||
vscode.bool_setting("macOptionIsMeta", &mut current.option_as_meta);
|
||||
vscode.usize_setting("scrollback", &mut current.max_scroll_history_lines);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue