Cargo.lock 🔗
@@ -7034,7 +7034,6 @@ dependencies = [
"num_cpus",
"outline",
"parking_lot 0.11.2",
- "plugin",
"plugin_runtime",
"postage",
"project",
Isaac Clayton created
Cargo.lock | 1
crates/plugin_macros/Cargo.toml | 2
crates/plugin_runtime/README.md | 13 ++
crates/plugin_runtime/build.rs | 3
crates/plugin_runtime/src/lib.rs | 7 -
crates/zed/Cargo.toml | 2
crates/zed/src/languages.rs | 3
crates/zed/src/languages/language_plugin.rs | 19 ----
plugins/json_language/src/sketch.rs | 88 -----------------------
9 files changed, 16 insertions(+), 122 deletions(-)
@@ -7034,7 +7034,6 @@ dependencies = [
"num_cpus",
"outline",
"parking_lot 0.11.2",
- "plugin",
"plugin_runtime",
"postage",
"project",
@@ -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"
+bincode = "1.3"
@@ -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<f64>) -> Vec<f64> {
x.into_iter().map(|x| x * 2.0).collect()
}
```
-All the serialization code is automatically generated by `#[bind]`.
+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<u8>;
+```
+
+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]`.
@@ -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();
@@ -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(
@@ -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"] }
@@ -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<LanguageRegistry>, executor: Arc<Background>) {
(
"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,
@@ -11,7 +11,6 @@ use util::ResultExt;
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
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<Background>) -> Result<PluginLspAdapter> {
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<dyn HttpClient>,
) -> Result<Box<dyn 'static + Send + Any>> {
- // let versions: Result<Option<String>> = call_block!(self, "fetch_latest_server_version", ());
let runtime = self.runtime.clone();
let function = self.fetch_latest_server_version;
self.executor
@@ -1,88 +0,0 @@
-
-use zed_plugin::RopeRef;
-
-
-// Host
-struct Handles {
- items: Vec<Box<dyn Any>>,
-}
-
-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::<Rope>(arg.0);
- let rope = Arc::from_raw(ptr);
- let result = rope.len();
- Arc::leak(rope);
- result
- });
- }
-
- fn to_handle(self) -> Handle<Rope> {
- 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