mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-28 09:54:33 +00:00
Add placeholder for extension slash commands (#12387)
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. <img width="644" alt="Screenshot 2024-05-28 at 12 15 07 PM" src="https://github.com/zed-industries/zed/assets/1486634/11761797-5ccc-4209-8b00-70b714f10a78"> Release Notes: - N/A
This commit is contained in:
parent
ac7aca335d
commit
01e86881f0
3 changed files with 19 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3774,6 +3774,7 @@ dependencies = [
|
||||||
"task",
|
"task",
|
||||||
"theme",
|
"theme",
|
||||||
"toml 0.8.10",
|
"toml 0.8.10",
|
||||||
|
"ui",
|
||||||
"url",
|
"url",
|
||||||
"util",
|
"util",
|
||||||
"wasm-encoder",
|
"wasm-encoder",
|
||||||
|
|
|
@ -39,6 +39,7 @@ serde_json.workspace = true
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
theme.workspace = true
|
theme.workspace = true
|
||||||
toml.workspace = true
|
toml.workspace = true
|
||||||
|
ui.workspace = true
|
||||||
url.workspace = true
|
url.workspace = true
|
||||||
util.workspace = true
|
util.workspace = true
|
||||||
wasm-encoder.workspace = true
|
wasm-encoder.workspace = true
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
use crate::wasm_host::{WasmExtension, WasmHost};
|
use std::sync::{atomic::AtomicBool, Arc};
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandOutputSection};
|
use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandOutputSection};
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use gpui::{AppContext, IntoElement, Task, WeakView, WindowContext};
|
use gpui::{AppContext, IntoElement, Task, WeakView, WindowContext};
|
||||||
use language::LspAdapterDelegate;
|
use language::LspAdapterDelegate;
|
||||||
use std::sync::{atomic::AtomicBool, Arc};
|
use ui::{prelude::*, ButtonLike, ElevationIndex};
|
||||||
use wasmtime_wasi::WasiView;
|
use wasmtime_wasi::WasiView;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
use crate::wasm_host::{WasmExtension, WasmHost};
|
||||||
|
|
||||||
pub struct ExtensionSlashCommand {
|
pub struct ExtensionSlashCommand {
|
||||||
pub(crate) extension: WasmExtension,
|
pub(crate) extension: WasmExtension,
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
@ -48,6 +51,7 @@ impl SlashCommand for ExtensionSlashCommand {
|
||||||
delegate: Arc<dyn LspAdapterDelegate>,
|
delegate: Arc<dyn LspAdapterDelegate>,
|
||||||
cx: &mut WindowContext,
|
cx: &mut WindowContext,
|
||||||
) -> Task<Result<SlashCommandOutput>> {
|
) -> Task<Result<SlashCommandOutput>> {
|
||||||
|
let command_name = SharedString::from(self.command.name.clone());
|
||||||
let argument = argument.map(|arg| arg.to_string());
|
let argument = argument.map(|arg| arg.to_string());
|
||||||
let text = cx.background_executor().spawn(async move {
|
let text = cx.background_executor().spawn(async move {
|
||||||
let output = self
|
let output = self
|
||||||
|
@ -82,8 +86,17 @@ impl SlashCommand for ExtensionSlashCommand {
|
||||||
text,
|
text,
|
||||||
sections: vec![SlashCommandOutputSection {
|
sections: vec![SlashCommandOutputSection {
|
||||||
range,
|
range,
|
||||||
render_placeholder: Arc::new(|_, _, _| {
|
render_placeholder: Arc::new({
|
||||||
"TODO: Extension command output".into_any_element()
|
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()
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue