From 01e86881f0dc793c1a54751f80455c37d05afc71 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 28 May 2024 12:16:31 -0400 Subject: [PATCH] Add placeholder for extension slash commands (#12387) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds a slightly better placeholder for extension slash commands than the current "TODO" text. Right now we display the command name and an arbitrary icon. Screenshot 2024-05-28 at 12 15 07 PM Release Notes: - N/A --- Cargo.lock | 1 + crates/extension/Cargo.toml | 1 + .../extension/src/extension_slash_command.rs | 21 +++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 307ce3aaf8..436a8795d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3774,6 +3774,7 @@ dependencies = [ "task", "theme", "toml 0.8.10", + "ui", "url", "util", "wasm-encoder", diff --git a/crates/extension/Cargo.toml b/crates/extension/Cargo.toml index 231318cd69..08b5250c3f 100644 --- a/crates/extension/Cargo.toml +++ b/crates/extension/Cargo.toml @@ -39,6 +39,7 @@ serde_json.workspace = true settings.workspace = true theme.workspace = true toml.workspace = true +ui.workspace = true url.workspace = true util.workspace = true wasm-encoder.workspace = true diff --git a/crates/extension/src/extension_slash_command.rs b/crates/extension/src/extension_slash_command.rs index 72ca429ce7..e5de0fe852 100644 --- a/crates/extension/src/extension_slash_command.rs +++ b/crates/extension/src/extension_slash_command.rs @@ -1,13 +1,16 @@ -use crate::wasm_host::{WasmExtension, WasmHost}; +use std::sync::{atomic::AtomicBool, Arc}; + use anyhow::{anyhow, Result}; use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandOutputSection}; use futures::FutureExt; use gpui::{AppContext, IntoElement, Task, WeakView, WindowContext}; use language::LspAdapterDelegate; -use std::sync::{atomic::AtomicBool, Arc}; +use ui::{prelude::*, ButtonLike, ElevationIndex}; use wasmtime_wasi::WasiView; use workspace::Workspace; +use crate::wasm_host::{WasmExtension, WasmHost}; + pub struct ExtensionSlashCommand { pub(crate) extension: WasmExtension, #[allow(unused)] @@ -48,6 +51,7 @@ impl SlashCommand for ExtensionSlashCommand { delegate: Arc, cx: &mut WindowContext, ) -> Task> { + let command_name = SharedString::from(self.command.name.clone()); let argument = argument.map(|arg| arg.to_string()); let text = cx.background_executor().spawn(async move { let output = self @@ -82,8 +86,17 @@ impl SlashCommand for ExtensionSlashCommand { text, sections: vec![SlashCommandOutputSection { range, - render_placeholder: Arc::new(|_, _, _| { - "TODO: Extension command output".into_any_element() + render_placeholder: Arc::new({ + let command_name = command_name.clone(); + move |id, unfold, _cx| { + ButtonLike::new(id) + .style(ButtonStyle::Filled) + .layer(ElevationIndex::ElevatedSurface) + .child(Icon::new(IconName::Code)) + .child(Label::new(command_name.clone())) + .on_click(move |_event, cx| unfold(cx)) + .into_any_element() + } }), }], })