assistant_slash_command.rs

 1mod slash_command_registry;
 2
 3use anyhow::Result;
 4use gpui::{AnyElement, AppContext, ElementId, Task, WeakView, WindowContext};
 5use language::LspAdapterDelegate;
 6pub use slash_command_registry::*;
 7use std::sync::{atomic::AtomicBool, Arc};
 8use workspace::Workspace;
 9
10pub fn init(cx: &mut AppContext) {
11    SlashCommandRegistry::default_global(cx);
12}
13
14pub trait SlashCommand: 'static + Send + Sync {
15    fn name(&self) -> String;
16    fn description(&self) -> String;
17    fn tooltip_text(&self) -> String;
18    fn complete_argument(
19        &self,
20        query: String,
21        cancel: Arc<AtomicBool>,
22        cx: &mut AppContext,
23    ) -> Task<Result<Vec<String>>>;
24    fn requires_argument(&self) -> bool;
25    fn run(
26        self: Arc<Self>,
27        argument: Option<&str>,
28        workspace: WeakView<Workspace>,
29        // TODO: We're just using the `LspAdapterDelegate` here because that is
30        // what the extension API is already expecting.
31        //
32        // It may be that `LspAdapterDelegate` needs a more general name, or
33        // perhaps another kind of delegate is needed here.
34        delegate: Arc<dyn LspAdapterDelegate>,
35        cx: &mut WindowContext,
36    ) -> Task<Result<SlashCommandOutput>>;
37}
38
39pub type RenderFoldPlaceholder = Arc<
40    dyn Send
41        + Sync
42        + Fn(ElementId, Arc<dyn Fn(&mut WindowContext)>, &mut WindowContext) -> AnyElement,
43>;
44
45pub struct SlashCommandOutput {
46    pub text: String,
47    pub render_placeholder: RenderFoldPlaceholder,
48}