zed_extension_api: Return structured slash command completions (#13879)

This PR updates the extension API to use structured slash command
completions instead of plain strings.

This allows slash commands defined in extensions to take advantage of
the improvements made in #13876.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-05 14:08:42 -04:00 committed by GitHub
parent 950e7e5414
commit 61e4b6413a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 15 deletions

View file

@ -4,7 +4,7 @@ use std::fs;
use zed::lsp::CompletionKind;
use zed::{
CodeLabel, CodeLabelSpan, HttpRequest, KeyValueStore, LanguageServerId, SlashCommand,
SlashCommandOutput, SlashCommandOutputSection,
SlashCommandArgumentCompletion, SlashCommandOutput, SlashCommandOutputSection,
};
use zed_extension_api::{self as zed, Result};
@ -154,12 +154,24 @@ impl zed::Extension for GleamExtension {
&self,
command: SlashCommand,
_query: String,
) -> Result<Vec<String>, String> {
) -> Result<Vec<SlashCommandArgumentCompletion>, String> {
match command.name.as_str() {
"gleam-project" => Ok(vec![
"apple".to_string(),
"banana".to_string(),
"cherry".to_string(),
SlashCommandArgumentCompletion {
label: "apple".to_string(),
new_text: "Apple".to_string(),
run_command: false,
},
SlashCommandArgumentCompletion {
label: "banana".to_string(),
new_text: "Banana".to_string(),
run_command: false,
},
SlashCommandArgumentCompletion {
label: "cherry".to_string(),
new_text: "Cherry".to_string(),
run_command: true,
},
]),
_ => Ok(Vec::new()),
}