diff --git a/crates/plugin_runtime/src/plugin.rs b/crates/plugin_runtime/src/plugin.rs index 27633d9eb9..a276213dcc 100644 --- a/crates/plugin_runtime/src/plugin.rs +++ b/crates/plugin_runtime/src/plugin.rs @@ -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 { + 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>(self, module: T) -> Result { + 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, plugin: PluginBuilder) -> Result { + 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, diff --git a/crates/zed/src/languages/language_plugin.rs b/crates/zed/src/languages/language_plugin.rs index 74e29afdfb..9c7796b4b2 100644 --- a/crates/zed/src/languages/language_plugin.rs +++ b/crates/zed/src/languages/language_plugin.rs @@ -10,16 +10,20 @@ use util::ResultExt; pub async fn new_json(executor: Arc) -> Result { 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?; diff --git a/plugins/json_language/src/lib.rs b/plugins/json_language/src/lib.rs index 11be117129..9809085547 100644 --- a/plugins/json_language/src/lib.rs +++ b/plugins/json_language/src/lib.rs @@ -7,77 +7,11 @@ use std::path::PathBuf; #[import] fn command(string: &str) -> Option>; -// #[no_mangle] -// // TODO: switch len from usize to u32? -// pub extern "C" fn #outer_fn_name(ptr: *const u8, len: usize) -> *const ::plugin::__Buffer { -// // setup -// let buffer = ::plugin::__Buffer { ptr, len }; -// let data = unsafe { buffer.to_vec() }; - -// // operation -// let data: #ty = match ::plugin::bincode::deserialize(&data) { -// Ok(d) => d, -// Err(e) => panic!("Data passed to function not deserializable."), -// }; -// let result = #inner_fn_name(#args); -// let new_data: Result, _> = ::plugin::bincode::serialize(&result); -// let new_data = new_data.unwrap(); - -// // teardown -// let new_buffer = unsafe { ::plugin::__Buffer::from_vec(new_data) }; -// return new_buffer.leak_to_heap(); -// } - -// extern "C" { -// fn __command(buffer: u64) -> u64; -// } - -// #[no_mangle] -// fn command(string: &str) -> Option> { -// dbg!("executing command: {}", string); -// // setup -// let data = string; -// let data = ::plugin::bincode::serialize(&data).unwrap(); -// let buffer = unsafe { ::plugin::__Buffer::from_vec(data) }; - -// // operation -// let new_buffer = unsafe { __command(buffer.into_u64()) }; -// let new_data = unsafe { ::plugin::__Buffer::from_u64(new_buffer).to_vec() }; -// let new_data: Option> = match ::plugin::bincode::deserialize(&new_data) { -// Ok(d) => d, -// Err(e) => panic!("Data returned from function not deserializable."), -// }; - -// // teardown -// return new_data; -// } - -// TODO: some sort of macro to generate ABI bindings -// extern "C" { -// pub fn hello(item: u32) -> u32; -// pub fn bye(item: u32) -> u32; -// } - -// #[bind] -// pub async fn name(u32) -> u32 { - -// } - -// #[no_mangle] -// pub extern "C" fn very_unique_name_of_course() -> impl std::future::Future { -// async move { -// std::fs::read_to_string("heck.txt").unwrap().len() as u32 -// } -// } - const BIN_PATH: &'static str = "node_modules/vscode-json-languageserver/bin/vscode-json-languageserver"; #[export] pub fn name() -> &'static str { - // let number = unsafe { hello(27) }; - // let number = unsafe { bye(28) }; - // println!("got: {}", number); "vscode-json-languageserver" } @@ -101,7 +35,6 @@ pub fn fetch_latest_server_version() -> Option { // } let output = String::from_utf8(output).unwrap(); - dbg!(&output); let mut info: NpmInfo = serde_json::from_str(&output).ok()?; info.versions.pop() @@ -120,7 +53,6 @@ pub fn fetch_server_binary(container_dir: PathBuf, version: String) -> Result Result Option { let mut last_version_dir = None; - println!("reading directory"); let mut entries = fs::read_dir(&container_dir).ok()?; while let Some(entry) = entries.next() { - println!("looking at entries"); let entry = entry.ok()?; - println!("some more stuff"); if entry.file_type().ok()?.is_dir() { - println!("this is it!"); - last_version_dir = Some(entry.path()); } } let last_version_dir = last_version_dir?; - println!("here we go"); let bin_path = last_version_dir.join(BIN_PATH); if bin_path.exists() { dbg!(&bin_path);