From 973498e075999b295cf5fd3910be9fbc34a77976 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 20 Nov 2024 10:53:51 -0500 Subject: [PATCH] context_servers: Make `settings` field show up in settings completions (#20905) This PR fixes an issue where the `settings` field for a context server would not show up in the completions when editing the Zed settings. It seems that `schemars` doesn't like the `serde_json::Value` as a setting type when generating the JSON Schema. To address this, we are using a custom schema of an empty object (as we don't yet have any other information as to the structure of a given context server's settings). Release Notes: - context_servers: Fixed `settings` field not being suggested in completions when editing `settings.json`. --- crates/context_servers/src/manager.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/context_servers/src/manager.rs b/crates/context_servers/src/manager.rs index fc0c77e821b6b94fc18b92d0a9d09782834ba9a8..9b9520e223b867ce2156ab7911b23cdf6d5e4a8d 100644 --- a/crates/context_servers/src/manager.rs +++ b/crates/context_servers/src/manager.rs @@ -24,6 +24,8 @@ use gpui::{AsyncAppContext, EventEmitter, Model, ModelContext, Subscription, Tas use log; use parking_lot::RwLock; use project::Project; +use schemars::gen::SchemaGenerator; +use schemars::schema::{InstanceType, Schema, SchemaObject}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use settings::{Settings, SettingsSources, SettingsStore}; @@ -43,9 +45,17 @@ pub struct ContextServerSettings { #[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)] pub struct ServerConfig { pub command: Option, + #[schemars(schema_with = "server_config_settings_json_schema")] pub settings: Option, } +fn server_config_settings_json_schema(_generator: &mut SchemaGenerator) -> Schema { + Schema::Object(SchemaObject { + instance_type: Some(InstanceType::Object.into()), + ..Default::default() + }) +} + #[derive(Deserialize, Serialize, Clone, PartialEq, Eq, JsonSchema, Debug)] pub struct ServerCommand { pub path: String,