
Files included with the diagnostics command now include the worktree name, making it more consistent with the way other commands work (`/active`, `/tabs`, `/file`). Also, the diagnostics command will now insert nothing when there are no diagnostics. Release Notes: - N/A
65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
mod slash_command_registry;
|
|
|
|
use anyhow::Result;
|
|
use gpui::{AnyElement, AppContext, ElementId, SharedString, Task, WeakView, WindowContext};
|
|
use language::{CodeLabel, LspAdapterDelegate};
|
|
use serde::{Deserialize, Serialize};
|
|
pub use slash_command_registry::*;
|
|
use std::{
|
|
ops::Range,
|
|
sync::{atomic::AtomicBool, Arc},
|
|
};
|
|
use workspace::{ui::IconName, 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: Arc<Self>,
|
|
query: String,
|
|
cancel: Arc<AtomicBool>,
|
|
workspace: Option<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,
|
|
>;
|
|
|
|
#[derive(Default)]
|
|
pub struct SlashCommandOutput {
|
|
pub text: String,
|
|
pub sections: Vec<SlashCommandOutputSection<usize>>,
|
|
pub run_commands_in_text: bool,
|
|
}
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
pub struct SlashCommandOutputSection<T> {
|
|
pub range: Range<T>,
|
|
pub icon: IconName,
|
|
pub label: SharedString,
|
|
}
|