From 3d29c9dd143737c8bffe4bacae8e701de3c6ee10 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 22 Oct 2025 02:34:51 +0200 Subject: [PATCH] fix: Wrap inner type in brackets --- lua_typed_macro/src/lib.rs | 4 ++-- src/lib.rs | 4 ++-- tests/notification.rs | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lua_typed_macro/src/lib.rs b/lua_typed_macro/src/lib.rs index b1adfb5..2d411f7 100644 --- a/lua_typed_macro/src/lib.rs +++ b/lua_typed_macro/src/lib.rs @@ -32,9 +32,9 @@ impl ToTokens for StructField { <#ty as Typed>::generate_members().unwrap_or("".to_string()) }); } else { - let optional = if self.optional { "?" } else { "" }; + let inner = if self.optional { "({})?" } else { "{}" }; - let format = format!("---@field {} {{}}{}\n", name, optional); + let format = format!("---@field {} {inner}\n", name); tokens.extend(quote! { format!(#format, <#ty as Typed>::type_name()) diff --git a/src/lib.rs b/src/lib.rs index e4a591d..ac45326 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,13 +160,13 @@ impl !Typed for () {} impl Typed for Option { fn type_name() -> String { - format!("{}?", ::type_name()) + format!("({})?", ::type_name()) } } impl Typed for Vec { fn type_name() -> String { - format!("{}[]", ::type_name()) + format!("({})[]", ::type_name()) } } diff --git a/tests/notification.rs b/tests/notification.rs index c0f1753..370d977 100644 --- a/tests/notification.rs +++ b/tests/notification.rs @@ -16,7 +16,7 @@ fn action_type() { ---@class ActionType ---@field action ---| "broadcast" - ---@field extras table? + ---@field extras (table)? local ActionType "#); } @@ -58,9 +58,9 @@ fn action() { ---@class Action ---@field action ---| "broadcast" - ---@field extras table? + ---@field extras (table)? ---@field label string - ---@field clear boolean? + ---@field clear (boolean)? local Action "#); } @@ -81,10 +81,10 @@ fn notification() { insta::assert_snapshot!(::generate_full().unwrap(), @r" ---@class Notification ---@field title string - ---@field message string? - ---@field tags string[]? - ---@field priority Priority? - ---@field actions Action[]? + ---@field message (string)? + ---@field tags ((string)[])? + ---@field priority (Priority)? + ---@field actions ((Action)[])? local Notification "); }