Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add font name completions to ui_font_family and terminal::font_family

Piotr Osiewiczff67d9dea033
diff --git a/Cargo.lock b/Cargo.lock
index 7b1fe5144c5..42416c2f245 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7775,6 +7775,7 @@ dependencies = [
"schemars",
"serde",
"serde_derive",
+ "serde_json",
"settings",
"shellexpand",
"smallvec",
diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml
index ce2a158e207..4dc253fd534 100644
--- a/crates/terminal/Cargo.toml
+++ b/crates/terminal/Cargo.toml
@@ -33,6 +33,7 @@ thiserror.workspace = true
lazy_static.workspace = true
serde.workspace = true
serde_derive.workspace = true
+serde_json.workspace = true
[dev-dependencies]
rand.workspace = true
diff --git a/crates/terminal/src/terminal_settings.rs b/crates/terminal/src/terminal_settings.rs
index 14cff3b5a69..b9b79c9c6b6 100644
--- a/crates/terminal/src/terminal_settings.rs
+++ b/crates/terminal/src/terminal_settings.rs
@@ -1,6 +1,12 @@
use gpui::{px, AbsoluteLength, AppContext, FontFeatures, Pixels};
-use schemars::JsonSchema;
+use schemars::{
+ gen::SchemaGenerator,
+ schema::{InstanceType, RootSchema, Schema, SchemaObject},
+ JsonSchema,
+};
use serde_derive::{Deserialize, Serialize};
+use serde_json::Value;
+use settings::SettingsJsonSchemaParams;
use std::{collections::HashMap, path::PathBuf};
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@@ -153,6 +159,39 @@ impl settings::Settings for TerminalSettings {
) -> anyhow::Result<Self> {
Self::load_via_json_merge(default_value, user_values)
}
+ fn json_schema(
+ generator: &mut SchemaGenerator,
+ _: &SettingsJsonSchemaParams,
+ cx: &AppContext,
+ ) -> RootSchema {
+ let mut root_schema = generator.root_schema_for::<Self::FileContent>();
+ let available_fonts = cx
+ .text_system()
+ .all_font_names()
+ .into_iter()
+ .map(Value::String)
+ .collect();
+ let fonts_schema = SchemaObject {
+ instance_type: Some(InstanceType::String.into()),
+ enum_values: Some(available_fonts),
+ ..Default::default()
+ };
+ root_schema
+ .definitions
+ .extend([("FontFamilies".into(), fonts_schema.into())]);
+ root_schema
+ .schema
+ .object
+ .as_mut()
+ .unwrap()
+ .properties
+ .extend([(
+ "font_family".to_owned(),
+ Schema::new_ref("#/definitions/FontFamilies".into()),
+ )]);
+
+ root_schema
+ }
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs
index 90c61ce2690..bced1874115 100644
--- a/crates/theme/src/settings.rs
+++ b/crates/theme/src/settings.rs
@@ -234,6 +234,10 @@ impl settings::Settings for ThemeSettings {
"buffer_font_family".to_owned(),
Schema::new_ref("#/definitions/FontFamilies".into()),
),
+ (
+ "ui_font_family".to_owned(),
+ Schema::new_ref("#/definitions/FontFamilies".into()),
+ ),
]);
root_schema