Switch from std::process::Command to smol::process::Command

This commit is contained in:
Isaac Clayton
2022-07-07 15:22:17 +02:00
parent 42fc278913
commit e5481e2e65
3 changed files with 13 additions and 77 deletions
+6
View File
@@ -66,6 +66,7 @@ impl PluginBuilder {
/// Create a new [`PluginBuilder`] with the given WASI context.
/// Using the default context is a safe bet, see [`new_with_default_context`].
pub fn new(wasi_ctx: WasiCtx) -> Result<Self, Error> {
dbg!("new plugin");
let mut config = Config::default();
config.async_support(true);
let engine = Engine::new(&config)?;
@@ -231,6 +232,7 @@ impl PluginBuilder {
/// Initializes a [`Plugin`] from a given compiled Wasm module.
/// Both binary (`.wasm`) and text (`.wat`) module formats are supported.
pub async fn init<T: AsRef<[u8]>>(self, module: T) -> Result<Plugin, Error> {
dbg!("initializing plugin");
Plugin::init(module.as_ref().to_vec(), self).await
}
}
@@ -296,6 +298,7 @@ impl Plugin {
impl Plugin {
async fn init(module: Vec<u8>, plugin: PluginBuilder) -> Result<Self, Error> {
dbg!("started initialization");
// initialize the WebAssembly System Interface context
let engine = plugin.engine;
let mut linker = plugin.linker;
@@ -311,6 +314,7 @@ impl Plugin {
},
);
let module = Module::new(&engine, module)?;
dbg!("created store");
// load the provided module into the asynchronous runtime
linker.module_async(&mut store, "", &module).await?;
@@ -325,6 +329,8 @@ impl Plugin {
free_buffer,
});
dbg!("bound funcitons");
Ok(Plugin {
engine,
module,
+7 -3
View File
@@ -10,16 +10,20 @@ use util::ResultExt;
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
let plugin = PluginBuilder::new_with_default_ctx()?
.host_function("command", |command: String| {
.host_function_async("command", |command: String| async move {
// TODO: actual thing
dbg!(&command);
let mut args = command.split(' ');
let command = args.next().unwrap();
std::process::Command::new(command)
smol::process::Command::new(command)
.args(args)
.output()
.await
.log_err()
.map(|output| dbg!(output.stdout))
.map(|output| {
dbg!("done running command");
output.stdout
})
})?
.init(include_bytes!("../../../../plugins/bin/json_language.wasm"))
.await?;