Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

assistant: Don't require a worktree to run slash commands (#15655)

Marshall Bowers88f29c835594
diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs
index c54a818206f..445d6a6df6b 100644
--- a/crates/assistant/src/assistant_panel.rs
+++ b/crates/assistant/src/assistant_panel.rs
@@ -1596,18 +1596,16 @@ impl ContextEditor {
cx: &mut ViewContext<Self>,
) {
if let Some(command) = SlashCommandRegistry::global(cx).command(name) {
- if let Some(lsp_adapter_delegate) = self.lsp_adapter_delegate.clone() {
- let argument = argument.map(ToString::to_string);
- let output = command.run(argument.as_deref(), workspace, lsp_adapter_delegate, cx);
- self.context.update(cx, |context, cx| {
- context.insert_command_output(
- command_range,
- output,
- insert_trailing_newline,
- cx,
- )
- });
- }
+ let argument = argument.map(ToString::to_string);
+ let output = command.run(
+ argument.as_deref(),
+ workspace,
+ self.lsp_adapter_delegate.clone(),
+ cx,
+ );
+ self.context.update(cx, |context, cx| {
+ context.insert_command_output(command_range, output, insert_trailing_newline, cx)
+ });
}
}
diff --git a/crates/assistant/src/context.rs b/crates/assistant/src/context.rs
index 5511223ab93..f52225c78c5 100644
--- a/crates/assistant/src/context.rs
+++ b/crates/assistant/src/context.rs
@@ -3414,7 +3414,7 @@ mod tests {
self: Arc<Self>,
_argument: Option<&str>,
_workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
_cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
Task::ready(Ok(SlashCommandOutput {
diff --git a/crates/assistant/src/slash_command/active_command.rs b/crates/assistant/src/slash_command/active_command.rs
index 0f46937560f..ad11e0ee081 100644
--- a/crates/assistant/src/slash_command/active_command.rs
+++ b/crates/assistant/src/slash_command/active_command.rs
@@ -46,7 +46,7 @@ impl SlashCommand for ActiveSlashCommand {
self: Arc<Self>,
_argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let output = workspace.update(cx, |workspace, cx| {
diff --git a/crates/assistant/src/slash_command/default_command.rs b/crates/assistant/src/slash_command/default_command.rs
index ccc9d1fbdb0..d01eea2f0dd 100644
--- a/crates/assistant/src/slash_command/default_command.rs
+++ b/crates/assistant/src/slash_command/default_command.rs
@@ -44,7 +44,7 @@ impl SlashCommand for DefaultSlashCommand {
self: Arc<Self>,
_argument: Option<&str>,
_workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let store = PromptStore::global(cx);
diff --git a/crates/assistant/src/slash_command/diagnostics_command.rs b/crates/assistant/src/slash_command/diagnostics_command.rs
index 1e9d0503a0c..d8413e286ed 100644
--- a/crates/assistant/src/slash_command/diagnostics_command.rs
+++ b/crates/assistant/src/slash_command/diagnostics_command.rs
@@ -158,7 +158,7 @@ impl SlashCommand for DiagnosticsSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(workspace) = workspace.upgrade() else {
diff --git a/crates/assistant/src/slash_command/docs_command.rs b/crates/assistant/src/slash_command/docs_command.rs
index 567d280eb78..864ef3c1ef5 100644
--- a/crates/assistant/src/slash_command/docs_command.rs
+++ b/crates/assistant/src/slash_command/docs_command.rs
@@ -242,7 +242,7 @@ impl SlashCommand for DocsSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
_workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(argument) = argument else {
diff --git a/crates/assistant/src/slash_command/fetch_command.rs b/crates/assistant/src/slash_command/fetch_command.rs
index 8934d68c163..e1a784f71ae 100644
--- a/crates/assistant/src/slash_command/fetch_command.rs
+++ b/crates/assistant/src/slash_command/fetch_command.rs
@@ -129,7 +129,7 @@ impl SlashCommand for FetchSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(argument) = argument else {
diff --git a/crates/assistant/src/slash_command/file_command.rs b/crates/assistant/src/slash_command/file_command.rs
index af35bacd2a5..b10a34e44e6 100644
--- a/crates/assistant/src/slash_command/file_command.rs
+++ b/crates/assistant/src/slash_command/file_command.rs
@@ -136,7 +136,7 @@ impl SlashCommand for FileSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(workspace) = workspace.upgrade() else {
diff --git a/crates/assistant/src/slash_command/now_command.rs b/crates/assistant/src/slash_command/now_command.rs
index 73f4f7b2565..ccd3d713d8e 100644
--- a/crates/assistant/src/slash_command/now_command.rs
+++ b/crates/assistant/src/slash_command/now_command.rs
@@ -44,7 +44,7 @@ impl SlashCommand for NowSlashCommand {
self: Arc<Self>,
_argument: Option<&str>,
_workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
_cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let now = Local::now();
diff --git a/crates/assistant/src/slash_command/project_command.rs b/crates/assistant/src/slash_command/project_command.rs
index c6c394f56bd..581b216b572 100644
--- a/crates/assistant/src/slash_command/project_command.rs
+++ b/crates/assistant/src/slash_command/project_command.rs
@@ -119,7 +119,7 @@ impl SlashCommand for ProjectSlashCommand {
self: Arc<Self>,
_argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let output = workspace.update(cx, |workspace, cx| {
diff --git a/crates/assistant/src/slash_command/prompt_command.rs b/crates/assistant/src/slash_command/prompt_command.rs
index 1edf2d51df0..24b4802230b 100644
--- a/crates/assistant/src/slash_command/prompt_command.rs
+++ b/crates/assistant/src/slash_command/prompt_command.rs
@@ -55,7 +55,7 @@ impl SlashCommand for PromptSlashCommand {
self: Arc<Self>,
title: Option<&str>,
_workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(title) = title else {
diff --git a/crates/assistant/src/slash_command/search_command.rs b/crates/assistant/src/slash_command/search_command.rs
index cdf1da7a9b7..979b1edb89f 100644
--- a/crates/assistant/src/slash_command/search_command.rs
+++ b/crates/assistant/src/slash_command/search_command.rs
@@ -54,7 +54,7 @@ impl SlashCommand for SearchSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(workspace) = workspace.upgrade() else {
diff --git a/crates/assistant/src/slash_command/symbols_command.rs b/crates/assistant/src/slash_command/symbols_command.rs
index 11a056f0daf..4788063aa1b 100644
--- a/crates/assistant/src/slash_command/symbols_command.rs
+++ b/crates/assistant/src/slash_command/symbols_command.rs
@@ -42,7 +42,7 @@ impl SlashCommand for OutlineSlashCommand {
self: Arc<Self>,
_argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let output = workspace.update(cx, |workspace, cx| {
diff --git a/crates/assistant/src/slash_command/tabs_command.rs b/crates/assistant/src/slash_command/tabs_command.rs
index 78be293bd7c..41da270d5ab 100644
--- a/crates/assistant/src/slash_command/tabs_command.rs
+++ b/crates/assistant/src/slash_command/tabs_command.rs
@@ -46,7 +46,7 @@ impl SlashCommand for TabsSlashCommand {
self: Arc<Self>,
_argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let open_buffers = workspace.update(cx, |workspace, cx| {
diff --git a/crates/assistant/src/slash_command/term_command.rs b/crates/assistant/src/slash_command/term_command.rs
index 90c3cb0fb95..277e13238f6 100644
--- a/crates/assistant/src/slash_command/term_command.rs
+++ b/crates/assistant/src/slash_command/term_command.rs
@@ -58,7 +58,7 @@ impl SlashCommand for TermSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
workspace: WeakView<Workspace>,
- _delegate: Arc<dyn LspAdapterDelegate>,
+ _delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let Some(workspace) = workspace.upgrade() else {
diff --git a/crates/assistant_slash_command/src/assistant_slash_command.rs b/crates/assistant_slash_command/src/assistant_slash_command.rs
index 5f917363a23..b33c2ce50b4 100644
--- a/crates/assistant_slash_command/src/assistant_slash_command.rs
+++ b/crates/assistant_slash_command/src/assistant_slash_command.rs
@@ -49,7 +49,7 @@ pub trait SlashCommand: 'static + Send + Sync {
//
// It may be that `LspAdapterDelegate` needs a more general name, or
// perhaps another kind of delegate is needed here.
- delegate: Arc<dyn LspAdapterDelegate>,
+ delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>>;
}
diff --git a/crates/extension/src/extension_slash_command.rs b/crates/extension/src/extension_slash_command.rs
index 086ddafbb01..a7bc1523b93 100644
--- a/crates/extension/src/extension_slash_command.rs
+++ b/crates/extension/src/extension_slash_command.rs
@@ -81,7 +81,7 @@ impl SlashCommand for ExtensionSlashCommand {
self: Arc<Self>,
argument: Option<&str>,
_workspace: WeakView<Workspace>,
- delegate: Arc<dyn LspAdapterDelegate>,
+ delegate: Option<Arc<dyn LspAdapterDelegate>>,
cx: &mut WindowContext,
) -> Task<Result<SlashCommandOutput>> {
let argument = argument.map(|arg| arg.to_string());
@@ -91,6 +91,9 @@ impl SlashCommand for ExtensionSlashCommand {
let this = self.clone();
move |extension, store| {
async move {
+ let delegate = delegate.ok_or_else(|| {
+ anyhow!("no worktree for extension slash command")
+ })?;
let resource = store.data_mut().table().push(delegate)?;
let output = extension
.call_run_slash_command(