This could still use some improvement UI-wise but the user experience
should be a lot better.
- [x] Show in "Window" application menu
- [x] Load prompt as it's selected in the picker
- [x] Refocus picker on `esc`
- [x] When creating a new prompt, if a new prompt already exists and is
unedited, activate it instead
- [x] Add `/default` command
- [x] Evaluate /commands on prompt insertion
- [x] Autocomplete /commands (but don't evaluate) during prompt editing
- [x] Show token count using the settings model, right-aligned in the
editor
- [x] Picker
- [x] Sorted alpha
- [x] 2 sublists
- Default
- Empty state: Star a prompt to add it to your default prompt
- Otherwise show prompts with star on hover
- All
- Move prompts with star on hover
Release Notes:
- N/A
63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
mod slash_command_registry;
|
|
|
|
use anyhow::Result;
|
|
use gpui::{AnyElement, AppContext, ElementId, Task, WeakView, WindowContext};
|
|
use language::{CodeLabel, LspAdapterDelegate};
|
|
pub use slash_command_registry::*;
|
|
use std::{
|
|
ops::Range,
|
|
sync::{atomic::AtomicBool, Arc},
|
|
};
|
|
use workspace::Workspace;
|
|
|
|
pub fn init(cx: &mut AppContext) {
|
|
SlashCommandRegistry::default_global(cx);
|
|
}
|
|
|
|
pub trait SlashCommand: 'static + Send + Sync {
|
|
fn name(&self) -> String;
|
|
fn label(&self, _cx: &AppContext) -> CodeLabel {
|
|
CodeLabel::plain(self.name(), None)
|
|
}
|
|
fn description(&self) -> String;
|
|
fn menu_text(&self) -> String;
|
|
fn complete_argument(
|
|
&self,
|
|
query: String,
|
|
cancel: Arc<AtomicBool>,
|
|
workspace: WeakView<Workspace>,
|
|
cx: &mut AppContext,
|
|
) -> Task<Result<Vec<String>>>;
|
|
fn requires_argument(&self) -> bool;
|
|
fn run(
|
|
self: Arc<Self>,
|
|
argument: Option<&str>,
|
|
workspace: WeakView<Workspace>,
|
|
// TODO: We're just using the `LspAdapterDelegate` here because that is
|
|
// what the extension API is already expecting.
|
|
//
|
|
// It may be that `LspAdapterDelegate` needs a more general name, or
|
|
// perhaps another kind of delegate is needed here.
|
|
delegate: Arc<dyn LspAdapterDelegate>,
|
|
cx: &mut WindowContext,
|
|
) -> Task<Result<SlashCommandOutput>>;
|
|
}
|
|
|
|
pub type RenderFoldPlaceholder = Arc<
|
|
dyn Send
|
|
+ Sync
|
|
+ Fn(ElementId, Arc<dyn Fn(&mut WindowContext)>, &mut WindowContext) -> AnyElement,
|
|
>;
|
|
|
|
pub struct SlashCommandOutput {
|
|
pub text: String,
|
|
pub sections: Vec<SlashCommandOutputSection<usize>>,
|
|
pub run_commands_in_text: bool,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct SlashCommandOutputSection<T> {
|
|
pub range: Range<T>,
|
|
pub render_placeholder: RenderFoldPlaceholder,
|
|
}
|