Make slash commands defined in extensions return SlashCommandOutput
(#13237)
This PR extends the interface for slash commands defined in extensions to have them return `SlashCommandOutput`. This allows for slash commands to return multiple output sections for a single piece of generated text. Note that we don't allow specifying the icon to display in the placeholder, as we don't want to commit to that in our API at the moment. Release Notes: - N/A
This commit is contained in:
parent
ca18549e02
commit
ad4e52842c
8 changed files with 73 additions and 38 deletions
|
@ -52,11 +52,9 @@ impl SlashCommand for ExtensionSlashCommand {
|
|||
delegate: Arc<dyn LspAdapterDelegate>,
|
||||
cx: &mut WindowContext,
|
||||
) -> Task<Result<SlashCommandOutput>> {
|
||||
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
|
||||
.extension
|
||||
let output = cx.background_executor().spawn(async move {
|
||||
self.extension
|
||||
.call({
|
||||
let this = self.clone();
|
||||
move |extension, store| {
|
||||
|
@ -77,19 +75,21 @@ impl SlashCommand for ExtensionSlashCommand {
|
|||
.boxed()
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
output.ok_or_else(|| anyhow!("no output from command: {}", self.command.name))
|
||||
.await
|
||||
});
|
||||
cx.foreground_executor().spawn(async move {
|
||||
let text = text.await?;
|
||||
let range = 0..text.len();
|
||||
let output = output.await?;
|
||||
Ok(SlashCommandOutput {
|
||||
text,
|
||||
sections: vec![SlashCommandOutputSection {
|
||||
range,
|
||||
icon: IconName::Code,
|
||||
label: command_name,
|
||||
}],
|
||||
text: output.text,
|
||||
sections: output
|
||||
.sections
|
||||
.into_iter()
|
||||
.map(|section| SlashCommandOutputSection {
|
||||
range: section.range.into(),
|
||||
icon: IconName::Code,
|
||||
label: section.label.into(),
|
||||
})
|
||||
.collect(),
|
||||
run_commands_in_text: false,
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue