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
|
@ -1,6 +1,9 @@
|
|||
use std::fs;
|
||||
use zed::lsp::CompletionKind;
|
||||
use zed::{CodeLabel, CodeLabelSpan, LanguageServerId, SlashCommand};
|
||||
use zed::{
|
||||
CodeLabel, CodeLabelSpan, LanguageServerId, SlashCommand, SlashCommandOutput,
|
||||
SlashCommandOutputSection,
|
||||
};
|
||||
use zed_extension_api::{self as zed, Result};
|
||||
|
||||
struct GleamExtension {
|
||||
|
@ -148,18 +151,24 @@ impl zed::Extension for GleamExtension {
|
|||
command: SlashCommand,
|
||||
_argument: Option<String>,
|
||||
worktree: &zed::Worktree,
|
||||
) -> Result<Option<String>, String> {
|
||||
) -> Result<SlashCommandOutput, String> {
|
||||
match command.name.as_str() {
|
||||
"gleam-project" => {
|
||||
let mut message = String::new();
|
||||
message.push_str("You are in a Gleam project.\n");
|
||||
let mut text = String::new();
|
||||
text.push_str("You are in a Gleam project.\n");
|
||||
|
||||
if let Some(gleam_toml) = worktree.read_text_file("gleam.toml").ok() {
|
||||
message.push_str("The `gleam.toml` is as follows:\n");
|
||||
message.push_str(&gleam_toml);
|
||||
text.push_str("The `gleam.toml` is as follows:\n");
|
||||
text.push_str(&gleam_toml);
|
||||
}
|
||||
|
||||
Ok(Some(message))
|
||||
Ok(SlashCommandOutput {
|
||||
sections: vec![SlashCommandOutputSection {
|
||||
range: (0..text.len()).into(),
|
||||
label: "gleam-project".to_string(),
|
||||
}],
|
||||
text,
|
||||
})
|
||||
}
|
||||
command => Err(format!("unknown slash command: \"{command}\"")),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue