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.

settings: Accept virtual font aliases in font family schema (#64830)

gasmyr7eccdcecb5c5
diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs
index 1a12c087832..dd0ec9fbb0c 100644
--- a/crates/settings/src/settings_store.rs
+++ b/crates/settings/src/settings_store.rs
@@ -45,6 +45,15 @@ use settings_json::{infer_json_indent_size, update_value_in_json_text};
pub const LSP_SETTINGS_SCHEMA_URL_PREFIX: &str = "zed://schemas/settings/lsp/";
+// GPUI resolves these aliases, but they are not part of the platform font inventory.
+const VIRTUAL_FONT_NAMES: [&str; 5] = [
+ ".SystemUIFont",
+ ".ZedMono",
+ ".ZedSans",
+ "Zed Plex Mono",
+ "Zed Plex Sans",
+];
+
pub trait SettingsKey: 'static + Send + Sync {
/// The name of a key within the JSON file from which this setting should
/// be deserialized. If this is `None`, then the setting will be deserialized
@@ -1295,9 +1304,14 @@ impl SettingsStore {
if !params.font_names.is_empty() {
replace_subschema::<FontFamilyName>(&mut generator, || {
+ let mut font_names = params.font_names.to_vec();
+ font_names.extend(VIRTUAL_FONT_NAMES.map(str::to_string));
+ font_names.sort_unstable();
+ font_names.dedup();
+
json_schema!({
"type": "string",
- "enum": params.font_names,
+ "enum": font_names,
})
});
}
@@ -3159,6 +3173,59 @@ mod tests {
)
}
+ #[test]
+ fn test_virtual_font_names_are_resolved() {
+ let system = "System Font";
+ let system_shared = SharedString::new_static(system);
+ for name in VIRTUAL_FONT_NAMES {
+ assert_ne!(
+ gpui::font_name_with_fallbacks(name, system),
+ name,
+ "{name} is listed in VIRTUAL_FONT_NAMES but not resolved by font_name_with_fallbacks"
+ );
+ let name_shared = SharedString::new_static(name);
+ assert_ne!(
+ gpui::font_name_with_fallbacks_shared(&name_shared, &system_shared),
+ &name_shared,
+ "{name} is listed in VIRTUAL_FONT_NAMES but not resolved by font_name_with_fallbacks_shared"
+ );
+ }
+ }
+
+ #[test]
+ fn test_font_family_schema_accepts_virtual_aliases() -> Result<()> {
+ let schema = SettingsStore::json_schema(&SettingsJsonSchemaParams {
+ language_names: &[],
+ font_names: &["IBM Plex Sans".to_string(), "Lilex".to_string()],
+ theme_names: &[],
+ icon_theme_names: &[],
+ lsp_adapter_names: &[],
+ action_names: &[],
+ action_documentation: &HashMap::default(),
+ deprecations: &HashMap::default(),
+ deprecation_messages: &HashMap::default(),
+ });
+
+ let font_names = schema
+ .pointer("/$defs/FontFamilyName/enum")
+ .and_then(Value::as_array)
+ .context("FontFamilyName schema should contain allowed font names")?;
+
+ for font_name in ["IBM Plex Sans", "Lilex"]
+ .into_iter()
+ .chain(VIRTUAL_FONT_NAMES)
+ {
+ assert!(
+ font_names
+ .iter()
+ .any(|value| value.as_str() == Some(font_name)),
+ "FontFamilyName schema should accept {font_name}"
+ );
+ }
+
+ Ok(())
+ }
+
#[gpui::test]
fn test_agent_profile_tool_schema(cx: &mut App) {
SettingsStore::test(cx);