Allow defining slash commands in extensions (#12255)
This PR adds initial support for defining slash commands for the Assistant from extensions. Slash commands are defined in an extension's `extension.toml`: ```toml [slash_commands.gleam-project] description = "Returns information about the current Gleam project." requires_argument = false ``` and then executed via the `run_slash_command` method on the `Extension` trait: ```rs impl Extension for GleamExtension { // ... fn run_slash_command( &self, command: SlashCommand, _argument: Option<String>, worktree: &zed::Worktree, ) -> Result<Option<String>, String> { match command.name.as_str() { "gleam-project" => Ok(Some("Yayyy".to_string())), command => Err(format!("unknown slash command: \"{command}\"")), } } } ``` Release Notes: - N/A
This commit is contained in:
parent
055a13a9b6
commit
82f5f36422
22 changed files with 310 additions and 14 deletions
|
@ -6,6 +6,7 @@ world extension {
|
|||
import nodejs;
|
||||
|
||||
use lsp.{completion, symbol};
|
||||
use slash-command.{slash-command};
|
||||
|
||||
/// Initializes the extension.
|
||||
export init-extension: func();
|
||||
|
@ -127,4 +128,7 @@ world extension {
|
|||
|
||||
export labels-for-completions: func(language-server-id: string, completions: list<completion>) -> result<list<option<code-label>>, string>;
|
||||
export labels-for-symbols: func(language-server-id: string, symbols: list<symbol>) -> result<list<option<code-label>>, string>;
|
||||
|
||||
/// Runs the provided slash command.
|
||||
export run-slash-command: func(command: slash-command, argument: option<string>, worktree: borrow<worktree>) -> result<option<string>, string>;
|
||||
}
|
||||
|
|
11
crates/extension_api/wit/since_v0.0.7/slash-command.wit
Normal file
11
crates/extension_api/wit/since_v0.0.7/slash-command.wit
Normal file
|
@ -0,0 +1,11 @@
|
|||
interface slash-command {
|
||||
/// A slash command for use in the Assistant.
|
||||
record slash-command {
|
||||
/// The name of the slash command.
|
||||
name: string,
|
||||
/// The description of the slash command.
|
||||
description: string,
|
||||
/// Whether this slash command requires an argument.
|
||||
requires-argument: bool,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue