diff --git a/crates/assistant/src/slash_command/active_command.rs b/crates/assistant/src/slash_command/active_command.rs index 235a38118a24a661d60b76c4e2679d057c7cb7a2..6ab8684362ea28a8a68c908ee0c93441aaa9de05 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 d1f657269222758941a0c533f4f1c83a896f8762..44ffdfcd11f1d4322d1f68df81cc5efa2ec21d6f 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 67afdae2dc7c167e744bfd6f22f7cd38822e37fb..c7e89a3fb8ed4be09e51b566a9144d4953db37ab 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 37be2928009133b767f2f882574fe07fea130ee5..cc675ecebe4c0e36bf8ddc83c6bdd41a3a5bf381 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 4fd7cd6a9aa311f181ee2f975824116f40901ae6..31792292d596de4dae32bd45492deb0e27dc331b 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 6db984469bc976ec5023f141d058428bf5c75ac2..43e5daa05b5788570604b51c4057a54565471941 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 d5f4d74404f891bbc63ad8e4ec75f600bb141ccc..b51c051e1180c1b2d9f2534d16744b424d7563b5 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 37610cc0177c1ddb71e97dccf6cb684a10e6fe22..ac4d77789e438ee500a9863c85eedb422a42d608 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 3104189eadf7d7b1c184096e7616a1d129544099..1658852e3cbddfe5b00a10f15ed366508caf79c4 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 ca2328ca6b92946a27b31cec20f587fb6f281e18..ad4beef5b339473f6b2030a6333ba5b37c38273d 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 6c4daf0afa7f26cf758f6087e30f9f78ab75679f..45220f8f4e38eb327b392c0a4d036285f5d66b17 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 691816ed7c6a8e31f41740bfb1c038ff957cba36..374cb817df8ec8652ed465935e2ba583e06c7331 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 23de82174c56b91ef987b5d073dacd0a95d60daa..e10007bfc2eec67c3c039bcdcb8be1a0cc994850 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 9963840b14423c9eb91a3283c0d3d18e32b4ba23..399f0a9119bb7b66c81f96dba5b42eb8bd3a01dd 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 a15826f2c18bd2aca29cb7c865685e55d0bd9878..5e9f3ad12f428ca90acf542a95a15e7f88c46b2a 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 253011194fc02d778844aa56cb0dcb98a820f7c9..522df4ccb3d7da0590baff1675666c8bf7d09f3f 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 1671fdf400b0a2537c063d3047c1cd6e0ed33e39..fd3ddf64ec7b60bfc5a7a0a4e1e4f5b440f0e796 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,