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:
parent
ec4d9ec111
commit
4d106a4b0b
6 changed files with 109 additions and 14 deletions
|
@ -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 {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue