From cf0a8a7a1a47cfda5a48348d8309a00a737f2b1e Mon Sep 17 00:00:00 2001 From: David Soria Parra <167242713+dsp-ant@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:13:03 +0100 Subject: [PATCH] context_servers: Add ability to provide labels for prompt outputs (#17077) Server can now include an optional description in a `prompts/get` response. Zed will displayed the description as label of the slash command. Release Notes: - context_servers: Servers can provide an optional description in `prompts/get` responses that is displayed as the slash command label. --- .../src/slash_command/context_server_command.rs | 10 +++++++--- crates/context_servers/src/protocol.rs | 4 ++-- crates/context_servers/src/types.rs | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/assistant/src/slash_command/context_server_command.rs b/crates/assistant/src/slash_command/context_server_command.rs index c39f132a7b..66c8ab21d3 100644 --- a/crates/assistant/src/slash_command/context_server_command.rs +++ b/crates/assistant/src/slash_command/context_server_command.rs @@ -84,11 +84,15 @@ impl SlashCommand for ContextServerSlashCommand { Ok(SlashCommandOutput { sections: vec![SlashCommandOutputSection { - range: 0..result.len(), + range: 0..(result.prompt.len()), icon: IconName::ZedAssistant, - label: SharedString::from(format!("Result from {}", prompt_name)), + label: SharedString::from( + result + .description + .unwrap_or(format!("Result from {}", prompt_name)), + ), }], - text: result, + text: result.prompt, run_commands_in_text: false, }) }) diff --git a/crates/context_servers/src/protocol.rs b/crates/context_servers/src/protocol.rs index 779ae89a05..1440f8248a 100644 --- a/crates/context_servers/src/protocol.rs +++ b/crates/context_servers/src/protocol.rs @@ -112,7 +112,7 @@ impl InitializedContextServerProtocol { &self, prompt: P, arguments: HashMap, - ) -> Result { + ) -> Result { self.check_capability(ServerCapability::Prompts)?; let params = types::PromptsGetParams { @@ -125,7 +125,7 @@ impl InitializedContextServerProtocol { .request(types::RequestType::PromptsGet.as_str(), params) .await?; - Ok(response.prompt) + Ok(response) } } diff --git a/crates/context_servers/src/types.rs b/crates/context_servers/src/types.rs index fb736d9de5..d880a45bd4 100644 --- a/crates/context_servers/src/types.rs +++ b/crates/context_servers/src/types.rs @@ -102,6 +102,7 @@ pub struct ResourcesListResponse { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PromptsGetResponse { + pub description: Option, pub prompt: String, }