Allow completing slash command arguments from extensions (#13240)
This PR extends the extension API with support for completing slash command arguments for slash commands defined in extensions. Release Notes: - N/A
This commit is contained in:
parent
ad4e52842c
commit
db0d843fb1
17 changed files with 90 additions and 19 deletions
|
@ -36,13 +36,34 @@ impl SlashCommand for ExtensionSlashCommand {
|
|||
}
|
||||
|
||||
fn complete_argument(
|
||||
&self,
|
||||
_query: String,
|
||||
self: Arc<Self>,
|
||||
query: String,
|
||||
_cancel: Arc<AtomicBool>,
|
||||
_workspace: Option<WeakView<Workspace>>,
|
||||
_cx: &mut AppContext,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<Result<Vec<String>>> {
|
||||
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(
|
||||
|
|
|
@ -257,6 +257,21 @@ impl Extension {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn call_complete_slash_command_argument(
|
||||
&self,
|
||||
store: &mut Store<WasmState>,
|
||||
command: &SlashCommand,
|
||||
query: &str,
|
||||
) -> Result<Result<Vec<String>, 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<WasmState>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue