Extract ExtensionSlashCommand to assistant_slash_command crate (#20617)

This PR extracts the `ExtensionSlashCommand` implementation to the
`assistant_slash_command` crate.

The slash command related methods have been added to the `Extension`
trait. We also create separate data types for the slash command data
within the `extension` crate so that we can talk about them without
depending on the `extension_host` or `assistant_slash_command`.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-11-13 14:34:58 -05:00 committed by GitHub
parent b913cf2e02
commit 254ce74036
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 309 additions and 161 deletions

View file

@ -1,5 +1,6 @@
pub mod extension_builder;
mod extension_manifest;
mod slash_command;
use std::path::{Path, PathBuf};
use std::sync::Arc;
@ -10,6 +11,7 @@ use gpui::Task;
use semantic_version::SemanticVersion;
pub use crate::extension_manifest::*;
pub use crate::slash_command::*;
#[async_trait]
pub trait WorktreeDelegate: Send + Sync + 'static {
@ -32,6 +34,19 @@ pub trait Extension: Send + Sync + 'static {
/// Returns the path to this extension's working directory.
fn work_dir(&self) -> Arc<Path>;
async fn complete_slash_command_argument(
&self,
command: SlashCommand,
arguments: Vec<String>,
) -> Result<Vec<SlashCommandArgumentCompletion>>;
async fn run_slash_command(
&self,
command: SlashCommand,
arguments: Vec<String>,
resource: Option<Arc<dyn WorktreeDelegate>>,
) -> Result<SlashCommandOutput>;
async fn suggest_docs_packages(&self, provider: Arc<str>) -> Result<Vec<String>>;
async fn index_docs(

View file

@ -0,0 +1,43 @@
use std::ops::Range;
/// A slash command for use in the Assistant.
#[derive(Debug, Clone)]
pub struct SlashCommand {
/// The name of the slash command.
pub name: String,
/// The description of the slash command.
pub description: String,
/// The tooltip text to display for the run button.
pub tooltip_text: String,
/// Whether this slash command requires an argument.
pub requires_argument: bool,
}
/// The output of a slash command.
#[derive(Debug, Clone)]
pub struct SlashCommandOutput {
/// The text produced by the slash command.
pub text: String,
/// The list of sections to show in the slash command placeholder.
pub sections: Vec<SlashCommandOutputSection>,
}
/// A section in the slash command output.
#[derive(Debug, Clone)]
pub struct SlashCommandOutputSection {
/// The range this section occupies.
pub range: Range<usize>,
/// The label to display in the placeholder for this section.
pub label: String,
}
/// A completion for a slash command argument.
#[derive(Debug, Clone)]
pub struct SlashCommandArgumentCompletion {
/// The label to display for this completion.
pub label: String,
/// The new text that should be inserted into the command when this completion is accepted.
pub new_text: String,
/// Whether the command should be run when accepting this completion.
pub run_command: bool,
}