fix: Wrap inner type in brackets

This commit is contained in:
2025-10-22 02:34:51 +02:00
parent 08f5c4533a
commit 3d29c9dd14
3 changed files with 11 additions and 11 deletions

View File

@@ -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())

View File

@@ -160,13 +160,13 @@ impl !Typed for () {}
impl<T: Typed> Typed for Option<T> {
fn type_name() -> String {
format!("{}?", <T as Typed>::type_name())
format!("({})?", <T as Typed>::type_name())
}
}
impl<T: Typed> Typed for Vec<T> {
fn type_name() -> String {
format!("{}[]", <T as Typed>::type_name())
format!("({})[]", <T as Typed>::type_name())
}
}

View File

@@ -16,7 +16,7 @@ fn action_type() {
---@class ActionType
---@field action
---| "broadcast"
---@field extras table<string, string>?
---@field extras (table<string, string>)?
local ActionType
"#);
}
@@ -58,9 +58,9 @@ fn action() {
---@class Action
---@field action
---| "broadcast"
---@field extras table<string, string>?
---@field extras (table<string, string>)?
---@field label string
---@field clear boolean?
---@field clear (boolean)?
local Action
"#);
}
@@ -81,10 +81,10 @@ fn notification() {
insta::assert_snapshot!(<Notification as Typed>::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
");
}