From 2b4e3bb332cfb75c71016f0dc7914d10f4a07686 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Fri, 17 Apr 2026 20:54:36 +0200 Subject: [PATCH] chore(plugin-api): enable enable_method_chaining --- Cargo.lock | 90 ++++++++++++------- Cargo.toml | 4 +- pumpkin-plugin-api/src/lib.rs | 1 + pumpkin-plugin-wit/v0.1.0/text.wit | 43 +++++---- .../loader/wasm/wasm_host/wit/v0_1_0/text.rs | 89 ++++++++++-------- 5 files changed, 131 insertions(+), 96 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b0c3fb4f..c90c79bc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1542,6 +1542,11 @@ name = "hashbrown" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" +dependencies = [ + "foldhash 0.2.0", + "serde", + "serde_core", +] [[package]] name = "hdrhistogram" @@ -2868,7 +2873,7 @@ dependencies = [ "tracing-subscriber", "ureq", "uuid", - "wasmparser 0.246.2", + "wasmparser 0.247.0", "wasmtime", "wasmtime-wasi", ] @@ -2962,7 +2967,7 @@ dependencies = [ "postcard", "tracing", "tracing-serde-structured", - "wit-bindgen 0.56.0", + "wit-bindgen 0.57.1", ] [[package]] @@ -4474,6 +4479,16 @@ dependencies = [ "wasmparser 0.246.2", ] +[[package]] +name = "wasm-encoder" +version = "0.247.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b6733b8b91d010a6ac5b0fb237dc46a19650bc4c67db66857e2e787d437204" +dependencies = [ + "leb128fmt", + "wasmparser 0.247.0", +] + [[package]] name = "wasm-metadata" version = "0.244.0" @@ -4488,14 +4503,14 @@ dependencies = [ [[package]] name = "wasm-metadata" -version = "0.246.2" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3e4c2aa916c425dcca61a6887d3e135acdee2c6d0ed51fd61c08d41ddaf62b1" +checksum = "665fe59e56cc9b419ca6fcca56673e3421d1a5011e3b65caf6b726fd9e041d10" dependencies = [ "anyhow", "indexmap", - "wasm-encoder 0.246.2", - "wasmparser 0.246.2", + "wasm-encoder 0.247.0", + "wasmparser 0.247.0", ] [[package]] @@ -4530,7 +4545,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71cde4757396defafd25417cfb36aa3161027d06d865b0c24baaae229aac005d" dependencies = [ "bitflags 2.11.1", - "hashbrown 0.16.1", + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.247.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e6fb4c2bee46c5ea4d40f8cdb5c131725cd976718ec56f1c8e82fbde5fa2a80" +dependencies = [ + "bitflags 2.11.1", + "hashbrown 0.17.0", "indexmap", "semver", "serde", @@ -5285,12 +5311,12 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.56.0" +version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7607d30e7e5e8fd5a0695f7cb8b2128829e0bf9dca7a1fe8c4d6ed3ca1058fce" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" dependencies = [ "bitflags 2.11.1", - "wit-bindgen-rust-macro 0.56.0", + "wit-bindgen-rust-macro 0.57.1", ] [[package]] @@ -5306,13 +5332,13 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.56.0" +version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda3a4ce47c08d27f575d451a60102bab5251776abd0a7a323d1f038eb6339ab" +checksum = "02dee27a2dc20d1008016c742ec9fc6ea498492994ba3750be7454cbc97ff04c" dependencies = [ "anyhow", "heck", - "wit-parser 0.246.2", + "wit-parser 0.247.0", ] [[package]] @@ -5333,18 +5359,18 @@ dependencies = [ [[package]] name = "wit-bindgen-rust" -version = "0.56.0" +version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "920a1c8c0f89397431db4900a7bf7c511b78e1b7068289fe812dc76e993f1491" +checksum = "b5007dae772945b7a5003d69d90a3a4a78929d41f19d004e980c4259a6af4484" dependencies = [ "anyhow", "heck", "indexmap", "prettyplease", "syn", - "wasm-metadata 0.246.2", - "wit-bindgen-core 0.56.0", - "wit-component 0.246.2", + "wasm-metadata 0.247.0", + "wit-bindgen-core 0.57.1", + "wit-component 0.247.0", ] [[package]] @@ -5364,9 +5390,9 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.56.0" +version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "857a143d2373abfcd31ad946393efe775ed8c90a2a365ce73c61bf38f36a1000" +checksum = "af9237d678e3513ad24e96fe98beacdc0db6405284ba2a2400418cf0d42caa89" dependencies = [ "anyhow", "macro-string", @@ -5374,8 +5400,8 @@ dependencies = [ "proc-macro2", "quote", "syn", - "wit-bindgen-core 0.56.0", - "wit-bindgen-rust 0.56.0", + "wit-bindgen-core 0.57.1", + "wit-bindgen-rust 0.57.1", ] [[package]] @@ -5399,9 +5425,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.246.2" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1936c26cb24b93dc36bf78fb5dc35c55cd37f66ecdc2d2663a717d9fb3ee951e" +checksum = "9d567162a6b9843080e5e0053f696623ff694bae8ae017c9ec536d1873bbe3d8" dependencies = [ "anyhow", "bitflags 2.11.1", @@ -5410,10 +5436,10 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.246.2", - "wasm-metadata 0.246.2", - "wasmparser 0.246.2", - "wit-parser 0.246.2", + "wasm-encoder 0.247.0", + "wasm-metadata 0.247.0", + "wasmparser 0.247.0", + "wit-parser 0.247.0", ] [[package]] @@ -5455,12 +5481,12 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.246.2" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd979042b5ff288607ccf3b314145435453f20fc67173195f91062d2289b204d" +checksum = "8ffe4064318cdf3c08cb99343b44c039fcefe61ccdf58aa9975285f13d74d1fc" dependencies = [ "anyhow", - "hashbrown 0.16.1", + "hashbrown 0.17.0", "id-arena", "indexmap", "log", @@ -5469,7 +5495,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.246.2", + "wasmparser 0.247.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7de9d01b0..57e4e682d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -180,8 +180,8 @@ notify = "8.2.0" wasmtime = "43.0" wasmtime-wasi = "43.0" -wit-bindgen = "0.56" -wasmparser = "0.246" +wit-bindgen = "0.57" +wasmparser = "0.247" postcard = { version = "1.1", features = ["alloc"] } tracing-serde-structured = "0.4" diff --git a/pumpkin-plugin-api/src/lib.rs b/pumpkin-plugin-api/src/lib.rs index d82cb99e9..06e436576 100644 --- a/pumpkin-plugin-api/src/lib.rs +++ b/pumpkin-plugin-api/src/lib.rs @@ -56,6 +56,7 @@ mod wit { skip: ["init-plugin"], path: "../pumpkin-plugin-wit/v0.1.0", world: "plugin", + enable_method_chaining: true }); use super::Component; diff --git a/pumpkin-plugin-wit/v0.1.0/text.wit b/pumpkin-plugin-wit/v0.1.0/text.wit index cad5d6f0d..c3c187208 100644 --- a/pumpkin-plugin-wit/v0.1.0/text.wit +++ b/pumpkin-plugin-wit/v0.1.0/text.wit @@ -5,37 +5,34 @@ interface text { text: static func(plain: string) -> text-component; translate: static func(key: string, %with: list) -> text-component; - add-child: func(child: text-component); - add-text: func(text: string); + add-child: func(child: text-component) -> text-component; + add-text: func(text: string) -> text-component; get-text: func() -> string; encode: func() -> list; // Style - - color-named: func(color: named-color); - color-rgb: func(color: rgb-color); - bold: func(value: bool); - italic: func(value: bool); - underlined: func(value: bool); - strikethrough: func(value: bool); - obfuscated: func(value: bool); + color-named: func(color: named-color) -> text-component; + color-rgb: func(color: rgb-color) -> text-component; + bold: func(value: bool) -> text-component; + italic: func(value: bool) -> text-component; + underlined: func(value: bool) -> text-component; + strikethrough: func(value: bool) -> text-component; + obfuscated: func(value: bool) -> text-component; /// Text inserted into chat when shift-clicked - insertion: func(text: string); - font: func(font: string); - shadow-color: func(color: argb-color); + insertion: func(text: string) -> text-component; + font: func(font: string) -> text-component; + shadow-color: func(color: argb-color) -> text-component; // Click events - - click-open-url: func(url: string); - click-run-command: func(command: string); - click-suggest-command: func(command: string); - click-copy-to-clipboard: func(text: string); + click-open-url: func(url: string) -> text-component; + click-run-command: func(command: string) -> text-component; + click-suggest-command: func(command: string) -> text-component; + click-copy-to-clipboard: func(text: string) -> text-component; // Hover events - - hover-show-text: func(text: text-component); + hover-show-text: func(text: text-component) -> text-component; /// Item data as SNBT string - hover-show-item: func(item: string); - hover-show-entity: func(entity-type: string, id: string, name: option); + hover-show-item: func(item: string) -> text-component; + hover-show-entity: func(entity-type: string, id: string, name: option) -> text-component; } -} +} \ No newline at end of file diff --git a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1_0/text.rs b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1_0/text.rs index 1b48cb5ab..6164495dc 100644 --- a/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1_0/text.rs +++ b/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1_0/text.rs @@ -101,22 +101,21 @@ impl pumpkin::plugin::text::HostTextComponent for PluginHostState { &mut self, text_component: Resource, child: Resource, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { let child_tc = self.take_text(&child)?.provider; let parent = self.get_text_mut(&text_component)?; - // Cloning here as noted in your TODO until builder pattern supports &mut self parent.provider = parent.provider.clone().add_child(child_tc); - Ok(()) + Ok(text_component) } async fn add_text( &mut self, text_component: Resource, text: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { let parent = self.get_text_mut(&text_component)?; parent.provider = parent.provider.clone().add_text(text); - Ok(()) + Ok(text_component) } async fn get_text( @@ -145,149 +144,161 @@ impl pumpkin::plugin::text::HostTextComponent for PluginHostState { &mut self, res: Resource, color: NamedColor, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.color = Some(Color::Named(map_named_color(color))); - Ok(()) + Ok(res) } async fn color_rgb( &mut self, res: Resource, color: RgbColor, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.color = Some(Color::Rgb(color::RGBColor::new(color.r, color.g, color.b))); - Ok(()) + Ok(res) } - async fn bold(&mut self, res: Resource, value: bool) -> wasmtime::Result<()> { + async fn bold( + &mut self, + res: Resource, + value: bool, + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.bold = Some(value); - Ok(()) + Ok(res) } - async fn italic(&mut self, res: Resource, value: bool) -> wasmtime::Result<()> { + async fn italic( + &mut self, + res: Resource, + value: bool, + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.italic = Some(value); - Ok(()) + Ok(res) } async fn underlined( &mut self, res: Resource, value: bool, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.underlined = Some(value); - Ok(()) + Ok(res) } async fn strikethrough( &mut self, res: Resource, value: bool, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.strikethrough = Some(value); - Ok(()) + Ok(res) } async fn obfuscated( &mut self, res: Resource, value: bool, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.obfuscated = Some(value); - Ok(()) + Ok(res) } async fn insertion( &mut self, res: Resource, text: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.insertion = Some(text); - Ok(()) + Ok(res) } - async fn font(&mut self, res: Resource, font: String) -> wasmtime::Result<()> { + async fn font( + &mut self, + res: Resource, + font: String, + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.font = Some(font); - Ok(()) + Ok(res) } async fn shadow_color( &mut self, res: Resource, color: ArgbColor, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.shadow_color = Some(color::ARGBColor::new(color.a, color.r, color.g, color.b)); - Ok(()) + Ok(res) } async fn click_open_url( &mut self, res: Resource, url: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.click_event = Some(ClickEvent::OpenUrl { url: Cow::Owned(url), }); - Ok(()) + Ok(res) } async fn click_run_command( &mut self, res: Resource, command: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.click_event = Some(ClickEvent::RunCommand { command: Cow::Owned(command), }); - Ok(()) + Ok(res) } async fn click_suggest_command( &mut self, res: Resource, command: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.click_event = Some(ClickEvent::SuggestCommand { command: Cow::Owned(command), }); - Ok(()) + Ok(res) } async fn click_copy_to_clipboard( &mut self, res: Resource, text: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.click_event = Some(ClickEvent::CopyToClipboard { value: Cow::Owned(text), }); - Ok(()) + Ok(res) } async fn hover_show_text( &mut self, res: Resource, text: Resource, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { let hover_tc = self.take_text(&text)?.provider; self.get_text_mut(&res)?.provider.0.style.hover_event = Some(HoverEvent::ShowText { value: vec![hover_tc.0], }); - Ok(()) + Ok(res) } async fn hover_show_item( &mut self, res: Resource, item: String, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { self.get_text_mut(&res)?.provider.0.style.hover_event = Some(HoverEvent::ShowItem { id: Cow::Owned(item), count: None, }); - Ok(()) + Ok(res) } async fn hover_show_entity( @@ -296,7 +307,7 @@ impl pumpkin::plugin::text::HostTextComponent for PluginHostState { entity_type: String, id: String, name: Option>, - ) -> wasmtime::Result<()> { + ) -> wasmtime::Result> { let name_val = match name { Some(r) => Some(vec![self.take_text(&r)?.provider.0]), None => None, @@ -306,7 +317,7 @@ impl pumpkin::plugin::text::HostTextComponent for PluginHostState { uuid: Cow::Owned(id), name: name_val, }); - Ok(()) + Ok(res) } async fn drop(&mut self, rep: Resource) -> wasmtime::Result<()> {