diff --git a/crates/extension/src/extension_slash_command.rs b/crates/extension/src/extension_slash_command.rs index a7bc1523b9..69283a9eb9 100644 --- a/crates/extension/src/extension_slash_command.rs +++ b/crates/extension/src/extension_slash_command.rs @@ -91,10 +91,11 @@ 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 resource = if let Some(delegate) = delegate { + Some(store.data_mut().table().push(delegate)?) + } else { + None + }; let output = extension .call_run_slash_command( store, diff --git a/crates/extension/src/wasm_host/wit.rs b/crates/extension/src/wasm_host/wit.rs index 2d81986443..a939e916a8 100644 --- a/crates/extension/src/wasm_host/wit.rs +++ b/crates/extension/src/wasm_host/wit.rs @@ -277,7 +277,7 @@ impl Extension { store: &mut Store, command: &SlashCommand, argument: Option<&str>, - resource: Resource>, + resource: Option>>, ) -> Result> { match self { Extension::V007(ext) => { diff --git a/crates/extension_api/src/extension_api.rs b/crates/extension_api/src/extension_api.rs index e0adf1b84b..e07df1171d 100644 --- a/crates/extension_api/src/extension_api.rs +++ b/crates/extension_api/src/extension_api.rs @@ -125,7 +125,7 @@ pub trait Extension: Send + Sync { &self, _command: SlashCommand, _argument: Option, - _worktree: &Worktree, + _worktree: Option<&Worktree>, ) -> Result { Err("`run_slash_command` not implemented".to_string()) } @@ -256,7 +256,7 @@ impl wit::Guest for Component { fn run_slash_command( command: SlashCommand, argument: Option, - worktree: &Worktree, + worktree: Option<&Worktree>, ) -> Result { extension().run_slash_command(command, argument, worktree) } 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 90f7c9978a..8b210d8bbc 100644 --- a/crates/extension_api/wit/since_v0.0.7/extension.wit +++ b/crates/extension_api/wit/since_v0.0.7/extension.wit @@ -133,7 +133,7 @@ world extension { 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; + export run-slash-command: func(command: slash-command, argument: option, worktree: option>) -> result; /// Indexes the docs for the specified package. export index-docs: func(provider-name: string, package-name: string, database: borrow) -> result<_, string>; diff --git a/extensions/gleam/src/gleam.rs b/extensions/gleam/src/gleam.rs index 1ed1c536fa..244bc8ec9b 100644 --- a/extensions/gleam/src/gleam.rs +++ b/extensions/gleam/src/gleam.rs @@ -181,7 +181,7 @@ impl zed::Extension for GleamExtension { &self, command: SlashCommand, argument: Option, - worktree: &zed::Worktree, + worktree: Option<&zed::Worktree>, ) -> Result { match command.name.as_str() { "gleam-docs" => { @@ -218,6 +218,8 @@ impl zed::Extension for GleamExtension { }) } "gleam-project" => { + let worktree = worktree.ok_or_else(|| "no worktree")?; + let mut text = String::new(); text.push_str("You are in a Gleam project.\n");