Introduce /search command to assistant (#12372)

This pull request introduces semantic search to the assistant using a
slash command:


https://github.com/zed-industries/zed/assets/482957/62f39eae-d7d5-46bf-a356-dd081ff88312

Moreover, this also adds a status to pending slash commands, so that we
can show when a query is running or whether it failed:

<img width="1588" alt="image"
src="https://github.com/zed-industries/zed/assets/482957/e8d85960-6275-4552-a068-85efb74cfde1">

I think this could be better design-wise, but seems like a pretty good
start.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-05-28 16:06:09 +02:00 committed by GitHub
parent 016a1444a7
commit 59662fbeb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 469 additions and 187 deletions

View file

@ -1,6 +1,6 @@
use crate::wasm_host::{WasmExtension, WasmHost};
use anyhow::{anyhow, Result};
use assistant_slash_command::{SlashCommand, SlashCommandOutput};
use assistant_slash_command::{SlashCommand, SlashCommandOutput, SlashCommandOutputSection};
use futures::FutureExt;
use gpui::{AppContext, IntoElement, Task, WeakView, WindowContext};
use language::LspAdapterDelegate;
@ -49,7 +49,7 @@ impl SlashCommand for ExtensionSlashCommand {
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let argument = argument.map(|arg| arg.to_string());
let output = cx.background_executor().spawn(async move {
let text = cx.background_executor().spawn(async move {
let output = self
.extension
.call({
@ -76,12 +76,16 @@ impl SlashCommand for ExtensionSlashCommand {
output.ok_or_else(|| anyhow!("no output from command: {}", self.command.name))
});
cx.foreground_executor().spawn(async move {
let output = output.await?;
let text = text.await?;
let range = 0..text.len();
Ok(SlashCommandOutput {
text: output,
render_placeholder: Arc::new(|_, _, _| {
"TODO: Extension command output".into_any_element()
}),
text,
sections: vec![SlashCommandOutputSection {
range,
render_placeholder: Arc::new(|_, _, _| {
"TODO: Extension command output".into_any_element()
}),
}],
})
})
}