zed_extension_api: Add simple process API (#25399)

This PR adds a simple API for working with processes to the extension
API.

The API is designed to mirror Rust's
[`std::process::Command`](https://doc.rust-lang.org/std/process/struct.Command.html).

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-02-22 13:05:36 -05:00 committed by GitHub
parent ec4d9ec111
commit 4d106a4b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 109 additions and 14 deletions

View file

@ -576,6 +576,35 @@ impl platform::Host for WasmState {
}
}
impl From<std::process::Output> for process::Output {
fn from(output: std::process::Output) -> Self {
Self {
status: output.status.code(),
stdout: output.stdout,
stderr: output.stderr,
}
}
}
impl process::Host for WasmState {
async fn run_command(
&mut self,
command: process::Command,
) -> wasmtime::Result<Result<process::Output, String>> {
maybe!(async {
let output = util::command::new_smol_command(command.command.as_str())
.args(&command.args)
.envs(command.env)
.output()
.await?;
Ok(output.into())
})
.await
.to_wasmtime_result()
}
}
#[async_trait]
impl slash_command::Host for WasmState {}