feat: Create local variable to allow for method definitions
This commit is contained in:
@@ -54,7 +54,8 @@ impl ToTokens for Struct {
|
||||
|
||||
tokens.extend(quote! {
|
||||
fn generate_header() -> Option<String> {
|
||||
Some(format!("---@class {}\n", <#name as Typed>::type_name()))
|
||||
let type_name = <#name as Typed>::type_name();
|
||||
Some(format!("---@class {type_name}\nlocal {type_name}\n"))
|
||||
}
|
||||
|
||||
fn generate_members() -> Option<String> {
|
||||
@@ -217,7 +218,8 @@ impl ToTokens for ExtTaggedEnum {
|
||||
|
||||
tokens.extend(quote! {
|
||||
fn generate_header() -> Option<String> {
|
||||
Some(format!("---@class {}\n", <#name as Typed>::type_name()))
|
||||
let type_name = <#name as Typed>::type_name();
|
||||
Some(format!("---@class {type_name}\nlocal {type_name}\n"))
|
||||
}
|
||||
|
||||
fn generate_members() -> Option<String> {
|
||||
|
||||
@@ -17,6 +17,7 @@ pub struct A {
|
||||
fn flatten() {
|
||||
insta::assert_snapshot!(<A as Typed>::generate_full().unwrap(), @r"
|
||||
---@class A
|
||||
local A
|
||||
---@field hello string
|
||||
---@field world boolean
|
||||
---@field cool integer
|
||||
|
||||
@@ -14,6 +14,7 @@ pub enum ActionType {
|
||||
fn action_type() {
|
||||
insta::assert_snapshot!(<ActionType as Typed>::generate_full().unwrap(), @r#"
|
||||
---@class ActionType
|
||||
local ActionType
|
||||
---@field action
|
||||
---| "broadcast"
|
||||
---@field extras table<string, string>?
|
||||
@@ -55,6 +56,7 @@ pub struct Action {
|
||||
fn action() {
|
||||
insta::assert_snapshot!(<Action as Typed>::generate_full().unwrap(), @r#"
|
||||
---@class Action
|
||||
local Action
|
||||
---@field action
|
||||
---| "broadcast"
|
||||
---@field extras table<string, string>?
|
||||
@@ -78,6 +80,7 @@ pub struct Notification {
|
||||
fn notification() {
|
||||
insta::assert_snapshot!(<Notification as Typed>::generate_full().unwrap(), @r"
|
||||
---@class Notification
|
||||
local Notification
|
||||
---@field title string
|
||||
---@field message string?
|
||||
---@field tags string[]?
|
||||
|
||||
@@ -11,13 +11,17 @@ struct Other {
|
||||
|
||||
#[test]
|
||||
fn rename() {
|
||||
insta::assert_snapshot!(<Rust as Typed>::generate_full().unwrap(), @"---@class Lua");
|
||||
insta::assert_snapshot!(<Rust as Typed>::generate_full().unwrap(), @r"
|
||||
---@class Lua
|
||||
local Lua
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_nested() {
|
||||
insta::assert_snapshot!(<Other as Typed>::generate_full().unwrap(), @r"
|
||||
---@class Other
|
||||
local Other
|
||||
---@field rust Lua
|
||||
");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user