diff --git a/crates/assistant/src/slash_command/active_command.rs b/crates/assistant/src/slash_command/active_command.rs index 235a38118a..6ab8684362 100644 --- a/crates/assistant/src/slash_command/active_command.rs +++ b/crates/assistant/src/slash_command/active_command.rs @@ -6,6 +6,7 @@ use anyhow::{anyhow, Result}; use editor::Editor; use gpui::{AppContext, Task, WeakView}; use language::LspAdapterDelegate; +use std::sync::atomic::AtomicBool; use std::sync::Arc; use ui::WindowContext; use workspace::Workspace; @@ -26,9 +27,9 @@ impl SlashCommand for ActiveSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, - _cancel: std::sync::Arc, + _cancel: Arc, _workspace: Option>, _cx: &mut AppContext, ) -> Task>> { diff --git a/crates/assistant/src/slash_command/default_command.rs b/crates/assistant/src/slash_command/default_command.rs index d1f6572692..44ffdfcd11 100644 --- a/crates/assistant/src/slash_command/default_command.rs +++ b/crates/assistant/src/slash_command/default_command.rs @@ -31,7 +31,7 @@ impl SlashCommand for DefaultSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, _cancellation_flag: Arc, _workspace: Option>, diff --git a/crates/assistant/src/slash_command/diagnostics_command.rs b/crates/assistant/src/slash_command/diagnostics_command.rs index 67afdae2dc..c7e89a3fb8 100644 --- a/crates/assistant/src/slash_command/diagnostics_command.rs +++ b/crates/assistant/src/slash_command/diagnostics_command.rs @@ -98,7 +98,7 @@ impl SlashCommand for DiagnosticsCommand { } fn complete_argument( - &self, + self: Arc, query: String, cancellation_flag: Arc, workspace: Option>, diff --git a/crates/assistant/src/slash_command/fetch_command.rs b/crates/assistant/src/slash_command/fetch_command.rs index 37be292800..cc675ecebe 100644 --- a/crates/assistant/src/slash_command/fetch_command.rs +++ b/crates/assistant/src/slash_command/fetch_command.rs @@ -113,7 +113,7 @@ impl SlashCommand for FetchSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, _cancel: Arc, _workspace: Option>, diff --git a/crates/assistant/src/slash_command/file_command.rs b/crates/assistant/src/slash_command/file_command.rs index 4fd7cd6a9a..31792292d5 100644 --- a/crates/assistant/src/slash_command/file_command.rs +++ b/crates/assistant/src/slash_command/file_command.rs @@ -101,7 +101,7 @@ impl SlashCommand for FileSlashCommand { } fn complete_argument( - &self, + self: Arc, query: String, cancellation_flag: Arc, workspace: Option>, diff --git a/crates/assistant/src/slash_command/now_command.rs b/crates/assistant/src/slash_command/now_command.rs index 6db984469b..43e5daa05b 100644 --- a/crates/assistant/src/slash_command/now_command.rs +++ b/crates/assistant/src/slash_command/now_command.rs @@ -29,7 +29,7 @@ impl SlashCommand for NowSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, _cancel: Arc, _workspace: Option>, diff --git a/crates/assistant/src/slash_command/project_command.rs b/crates/assistant/src/slash_command/project_command.rs index d5f4d74404..b51c051e11 100644 --- a/crates/assistant/src/slash_command/project_command.rs +++ b/crates/assistant/src/slash_command/project_command.rs @@ -102,7 +102,7 @@ impl SlashCommand for ProjectSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, _cancel: Arc, _workspace: Option>, diff --git a/crates/assistant/src/slash_command/prompt_command.rs b/crates/assistant/src/slash_command/prompt_command.rs index 37610cc017..ac4d77789e 100644 --- a/crates/assistant/src/slash_command/prompt_command.rs +++ b/crates/assistant/src/slash_command/prompt_command.rs @@ -28,7 +28,7 @@ impl SlashCommand for PromptSlashCommand { } fn complete_argument( - &self, + self: Arc, query: String, _cancellation_flag: Arc, _workspace: Option>, diff --git a/crates/assistant/src/slash_command/rustdoc_command.rs b/crates/assistant/src/slash_command/rustdoc_command.rs index 3104189ead..1658852e3c 100644 --- a/crates/assistant/src/slash_command/rustdoc_command.rs +++ b/crates/assistant/src/slash_command/rustdoc_command.rs @@ -107,7 +107,7 @@ impl SlashCommand for RustdocSlashCommand { } fn complete_argument( - &self, + self: Arc, query: String, _cancel: Arc, workspace: Option>, diff --git a/crates/assistant/src/slash_command/search_command.rs b/crates/assistant/src/slash_command/search_command.rs index ca2328ca6b..ad4beef5b3 100644 --- a/crates/assistant/src/slash_command/search_command.rs +++ b/crates/assistant/src/slash_command/search_command.rs @@ -47,7 +47,7 @@ impl SlashCommand for SearchSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, _cancel: Arc, _workspace: Option>, diff --git a/crates/assistant/src/slash_command/tabs_command.rs b/crates/assistant/src/slash_command/tabs_command.rs index 6c4daf0afa..45220f8f4e 100644 --- a/crates/assistant/src/slash_command/tabs_command.rs +++ b/crates/assistant/src/slash_command/tabs_command.rs @@ -31,7 +31,7 @@ impl SlashCommand for TabsSlashCommand { } fn complete_argument( - &self, + self: Arc, _query: String, _cancel: Arc, _workspace: Option>, diff --git a/crates/assistant_slash_command/src/assistant_slash_command.rs b/crates/assistant_slash_command/src/assistant_slash_command.rs index 691816ed7c..374cb817df 100644 --- a/crates/assistant_slash_command/src/assistant_slash_command.rs +++ b/crates/assistant_slash_command/src/assistant_slash_command.rs @@ -23,7 +23,7 @@ pub trait SlashCommand: 'static + Send + Sync { fn description(&self) -> String; fn menu_text(&self) -> String; fn complete_argument( - &self, + self: Arc, query: String, cancel: Arc, workspace: Option>, diff --git a/crates/extension/src/extension_slash_command.rs b/crates/extension/src/extension_slash_command.rs index 23de82174c..e10007bfc2 100644 --- a/crates/extension/src/extension_slash_command.rs +++ b/crates/extension/src/extension_slash_command.rs @@ -36,13 +36,34 @@ impl SlashCommand for ExtensionSlashCommand { } fn complete_argument( - &self, - _query: String, + self: Arc, + query: String, _cancel: Arc, _workspace: Option>, - _cx: &mut AppContext, + cx: &mut AppContext, ) -> Task>> { - Task::ready(Ok(Vec::new())) + cx.background_executor().spawn(async move { + self.extension + .call({ + let this = self.clone(); + move |extension, store| { + async move { + let completions = extension + .call_complete_slash_command_argument( + store, + &this.command, + query.as_ref(), + ) + .await? + .map_err(|e| anyhow!("{}", e))?; + + anyhow::Ok(completions) + } + .boxed() + } + }) + .await + }) } fn run( diff --git a/crates/extension/src/wasm_host/wit.rs b/crates/extension/src/wasm_host/wit.rs index 9963840b14..399f0a9119 100644 --- a/crates/extension/src/wasm_host/wit.rs +++ b/crates/extension/src/wasm_host/wit.rs @@ -257,6 +257,21 @@ impl Extension { } } + pub async fn call_complete_slash_command_argument( + &self, + store: &mut Store, + command: &SlashCommand, + query: &str, + ) -> Result, String>> { + match self { + Extension::V007(ext) => { + ext.call_complete_slash_command_argument(store, command, query) + .await + } + Extension::V001(_) | Extension::V004(_) | Extension::V006(_) => Ok(Ok(Vec::new())), + } + } + pub async fn call_run_slash_command( &self, store: &mut Store, diff --git a/crates/extension_api/src/extension_api.rs b/crates/extension_api/src/extension_api.rs index a15826f2c1..5e9f3ad12f 100644 --- a/crates/extension_api/src/extension_api.rs +++ b/crates/extension_api/src/extension_api.rs @@ -108,7 +108,16 @@ pub trait Extension: Send + Sync { None } - /// Runs the given slash command. + /// Returns the completions that should be shown when completing the provided slash command with the given query. + fn complete_slash_command_argument( + &self, + _command: SlashCommand, + _query: String, + ) -> Result, String> { + Ok(Vec::new()) + } + + /// Returns the output from running the provided slash command. fn run_slash_command( &self, _command: SlashCommand, @@ -225,6 +234,13 @@ impl wit::Guest for Component { Ok(labels) } + fn complete_slash_command_argument( + command: SlashCommand, + query: String, + ) -> Result, String> { + extension().complete_slash_command_argument(command, query) + } + fn run_slash_command( command: SlashCommand, argument: Option, diff --git a/crates/extension_api/wit/since_v0.0.7/extension.wit b/crates/extension_api/wit/since_v0.0.7/extension.wit index 253011194f..522df4ccb3 100644 --- a/crates/extension_api/wit/since_v0.0.7/extension.wit +++ b/crates/extension_api/wit/since_v0.0.7/extension.wit @@ -122,6 +122,9 @@ world extension { export labels-for-completions: func(language-server-id: string, completions: list) -> result>, string>; export labels-for-symbols: func(language-server-id: string, symbols: list) -> result>, string>; - /// Runs the provided slash command. + /// Returns the completions that should be shown when completing the provided slash command with the given query. + export complete-slash-command-argument: func(command: slash-command, query: string) -> result, string>; + + /// Returns the output from running the provided slash command. export run-slash-command: func(command: slash-command, argument: option, worktree: borrow) -> result; } diff --git a/extensions/gleam/src/gleam.rs b/extensions/gleam/src/gleam.rs index 1671fdf400..fd3ddf64ec 100644 --- a/extensions/gleam/src/gleam.rs +++ b/extensions/gleam/src/gleam.rs @@ -146,6 +146,21 @@ impl zed::Extension for GleamExtension { }) } + fn complete_slash_command_argument( + &self, + command: SlashCommand, + _query: String, + ) -> Result, String> { + match command.name.as_str() { + "gleam-project" => Ok(vec![ + "apple".to_string(), + "banana".to_string(), + "cherry".to_string(), + ]), + _ => Ok(Vec::new()), + } + } + fn run_slash_command( &self, command: SlashCommand,