diff --git a/Cargo.lock b/Cargo.lock index f3df25ce58..f690e0d07a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7034,7 +7034,6 @@ dependencies = [ "num_cpus", "outline", "parking_lot 0.11.2", - "plugin", "plugin_runtime", "postage", "project", diff --git a/crates/plugin_macros/Cargo.toml b/crates/plugin_macros/Cargo.toml index 1fa21a8fff..b0a2c4e09b 100644 --- a/crates/plugin_macros/Cargo.toml +++ b/crates/plugin_macros/Cargo.toml @@ -11,4 +11,4 @@ syn = { version = "1.0", features = ["full", "extra-traits"] } quote = "1.0" proc-macro2 = "1.0" serde = "1.0" -bincode = "1.3" \ No newline at end of file +bincode = "1.3" diff --git a/crates/plugin_runtime/README.md b/crates/plugin_runtime/README.md index abd6b1e37c..1bebeccaf2 100644 --- a/crates/plugin_runtime/README.md +++ b/crates/plugin_runtime/README.md @@ -39,10 +39,19 @@ Here's an example Rust Wasm plugin that doubles the value of every float in a `V ```rust use plugin::prelude::*; -#[bind] +#[export] pub fn double(mut x: Vec) -> Vec { x.into_iter().map(|x| x * 2.0).collect() } ``` -All the serialization code is automatically generated by `#[bind]`. \ No newline at end of file +All the serialization code is automatically generated by `#[export]`. + +You can specify functions that must be defined host-side by using the `#[import]` attribute. This attribute must be attached to a function signature: + +```rust +#[import] +fn run(command: String) -> Vec; +``` + +The `#[import]` macro will generate a function body that performs the proper serialization/deserialization needed to call out to the host rust runtime. Note that the same ABI is used for both `#[import]` and `#[export]`. \ No newline at end of file diff --git a/crates/plugin_runtime/build.rs b/crates/plugin_runtime/build.rs index 05bb65b2d8..e8120c9654 100644 --- a/crates/plugin_runtime/build.rs +++ b/crates/plugin_runtime/build.rs @@ -5,7 +5,7 @@ fn main() { let base = Path::new("../../plugins"); // println!("cargo:rerun-if-changed=../../plugins/*"); - println!("cargo:warning=Rebuilding plugins..."); + println!("cargo:warning=Precompiling plugins..."); let _ = std::fs::remove_dir_all(base.join("bin")); let _ = @@ -27,7 +27,6 @@ fn main() { let binaries = std::fs::read_dir(base.join("target/wasm32-wasi/release")) .expect("Could not find compiled plugins in target"); - println!("cargo:warning={:?}", binaries); let engine = create_engine(); diff --git a/crates/plugin_runtime/src/lib.rs b/crates/plugin_runtime/src/lib.rs index cf460f73cb..555d925874 100644 --- a/crates/plugin_runtime/src/lib.rs +++ b/crates/plugin_runtime/src/lib.rs @@ -36,8 +36,6 @@ mod tests { .host_function_async("import_half", |a: u32| async move { a / 2 }) .unwrap() .host_function_async("command_async", |command: String| async move { - // TODO: actual thing - dbg!(&command); let mut args = command.split(' '); let command = args.next().unwrap(); smol::process::Command::new(command) @@ -45,10 +43,7 @@ mod tests { .output() .await .ok() - .map(|output| { - dbg!("Did run command!"); - output.stdout - }) + .map(|output| output.stdout) }) .unwrap() .init( diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index e85824b692..68fa67d3b3 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -39,7 +39,6 @@ journal = { path = "../journal" } language = { path = "../language" } lsp = { path = "../lsp" } outline = { path = "../outline" } -plugin = { path = "../plugin" } plugin_runtime = { path = "../plugin_runtime" } project = { path = "../project" } project_panel = { path = "../project_panel" } @@ -102,7 +101,6 @@ tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", re tree-sitter-typescript = "0.20.1" url = "2.2" - [dev-dependencies] text = { path = "../text", features = ["test-support"] } editor = { path = "../editor", features = ["test-support"] } diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index f5660667d5..a45c4122e8 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -7,6 +7,7 @@ use util::ResultExt; mod c; mod go; mod installation; +mod json; mod language_plugin; mod python; mod rust; @@ -37,7 +38,7 @@ pub async fn init(languages: Arc, executor: Arc) { ( "json", tree_sitter_json::language(), - // Some(LspAdapter::new(json::JsonLspAdapter)), + // Some(LspAdapter::new(json::JsonLspAdapter).await), match language_plugin::new_json(executor).await.log_err() { Some(lang) => Some(LspAdapter::new(lang).await), None => None, diff --git a/crates/zed/src/languages/language_plugin.rs b/crates/zed/src/languages/language_plugin.rs index 664a3e2c0f..d205c262e2 100644 --- a/crates/zed/src/languages/language_plugin.rs +++ b/crates/zed/src/languages/language_plugin.rs @@ -11,7 +11,6 @@ use util::ResultExt; pub async fn new_json(executor: Arc) -> Result { let plugin = PluginBuilder::new_with_default_ctx()? .host_function_async("command", |command: String| async move { - dbg!(&command); let mut args = command.split(' '); let command = args.next().unwrap(); smol::process::Command::new(command) @@ -26,7 +25,6 @@ pub async fn new_json(executor: Arc) -> Result { include_bytes!("../../../../plugins/bin/json_language.wasm.pre"), ) .await?; - // smol::Timer::after(std::time::Duration::from_secs(5)).await; PluginLspAdapter::new(plugin, executor).await } @@ -58,22 +56,6 @@ impl PluginLspAdapter { } } -// struct Versions { -// language_version: String, -// server_version: String, -// } - -// TODO: is this the root cause? -// sketch: -// - smol command is run, hits await, switches -// - name is run, blocked on -// - smol command is still pending -// - name is stuck for some reason(?) -// - no progress made... -// - deadlock!!!? -// I wish there was high-level instrumentation for this... -// - it's totally a deadlock, the proof is in the pudding - #[async_trait] impl LspAdapterTrait for PluginLspAdapter { async fn name(&self) -> LanguageServerName { @@ -100,7 +82,6 @@ impl LspAdapterTrait for PluginLspAdapter { &self, _: Arc, ) -> Result> { - // let versions: Result> = call_block!(self, "fetch_latest_server_version", ()); let runtime = self.runtime.clone(); let function = self.fetch_latest_server_version; self.executor diff --git a/plugins/json_language/src/sketch.rs b/plugins/json_language/src/sketch.rs deleted file mode 100644 index def823fcd4..0000000000 --- a/plugins/json_language/src/sketch.rs +++ /dev/null @@ -1,88 +0,0 @@ - -use zed_plugin::RopeRef; - - -// Host -struct Handles { - items: Vec>, -} - -struct Rope; - -impl Link for Rope { - fn link(linker: &mut Linker) -> Result<()> { - linker.add(|this: &mut Rope| { - - }); - linker.func_wrap("env", "len", |handles, arg| { - let rope = handles.downcast::(arg.0); - let rope = Arc::from_raw(ptr); - let result = rope.len(); - Arc::leak(rope); - result - }); - } - - fn to_handle(self) -> Handle { - todo!() - } -} - -// -- Host - -pub fn edit_rope(&mut self) { - let rope: &mut Rope = self......rope(); - let handle: RopeRef = self.runtime.to_handle(rope); - self.runtime.call("edit_rope", handle); -} - -// Guest - -extern "C" long rope__len(u32 handle); - -struct RopeRef(u32); - -impl RopeRef { - fn len(&self) -> usize { - rope__len(self.0); - } -} - -pub fn edit_rope(rope: RopeRef) { - rope.len() -} - -// Host side --- - -pub struct Rope { .. } - -RopeRef(u32); - -impl Link for RopeRef { - pub fn init(&mut something) { - something.add("length", |rope| ) - } -} - -// --- - -extern "C" { - pub fn length(item: u32) -> u32; -} - -struct RopeRef { - handle: u32, -} - -pub fn length(ref: RopeRef) -> u32 { - ref.length() -} - -// Host side - -#[plugin_interface] -trait LspAdapter { - name() -> &'static str; -} - -// Guest side