From db73ccf0d1fa6d8732e59f37b5b3ecf3c790154c Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Mon, 22 Jul 2024 15:00:09 -0700 Subject: [PATCH 1/2] typegen: add module names --- typegen/src/main.rs | 1 + typegen/src/outform.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/typegen/src/main.rs b/typegen/src/main.rs index d1736ab..a14255c 100644 --- a/typegen/src/main.rs +++ b/typegen/src/main.rs @@ -107,6 +107,7 @@ hidetitle = true } let index = outform::ModuleIndex { + name: module.header.name.to_string(), description: module.header.description, details: module.details.to_string(), }; diff --git a/typegen/src/outform.rs b/typegen/src/outform.rs index 185cc5b..a7910f6 100644 --- a/typegen/src/outform.rs +++ b/typegen/src/outform.rs @@ -4,6 +4,7 @@ use serde::Serialize; #[derive(Debug, Serialize)] pub struct ModuleIndex { + pub name: String, pub description: String, pub details: String, } From 4b9a0e9ff218be74e80615aaea6bf39d42b00f77 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Mon, 22 Jul 2024 15:24:43 -0700 Subject: [PATCH 2/2] typegen: add module and name fields to type files --- typegen/src/outform.rs | 10 +++++++- typegen/src/resolver.rs | 53 ++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/typegen/src/outform.rs b/typegen/src/outform.rs index a7910f6..641d64c 100644 --- a/typegen/src/outform.rs +++ b/typegen/src/outform.rs @@ -9,10 +9,18 @@ pub struct ModuleIndex { pub details: String, } +#[derive(Debug, Serialize)] +pub struct TypeInfo { + pub name: String, + pub module: String, + #[serde(flatten)] + pub details: TypeDetails, +} + #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] #[serde(tag = "type")] -pub enum TypeInfo { +pub enum TypeDetails { Class(ClassInfo), Enum(EnumInfo), } diff --git a/typegen/src/resolver.rs b/typegen/src/resolver.rs index 8c2f609..984c582 100644 --- a/typegen/src/resolver.rs +++ b/typegen/src/resolver.rs @@ -211,37 +211,42 @@ pub fn resolve_types( None => HashMap::new(), }; - let type_ = outform::ClassInfo { - superclass, - description: class.description.clone(), - details: class.details.clone(), - flags: { - let mut flags = Vec::new(); + let type_ = outform::TypeInfo { + name: mapping.name.clone(), + module: mapping.module.clone().unwrap(), + details: outform::TypeDetails::Class(outform::ClassInfo { + superclass, + description: class.description.clone(), + details: class.details.clone(), + flags: { + let mut flags = Vec::new(); - if coreenum.is_some() { - flags.push(Flag::Enum); - } else if class.singleton { - flags.push(Flag::Singleton); - } else if class.uncreatable { - flags.push(Flag::Uncreatable); - } + if coreenum.is_some() { + flags.push(Flag::Enum); + } else if class.singleton { + flags.push(Flag::Singleton); + } else if class.uncreatable { + flags.push(Flag::Uncreatable); + } - flags - }, - properties, - functions, - signals, - variants, + flags + }, + properties, + functions, + signals, + variants, + }), }; - outtypes.insert(mapping.name.clone(), outform::TypeInfo::Class(type_)); + outtypes.insert(mapping.name.clone(), type_); } for enum_ in typespec.enums { if enum_.module.as_ref().map(|v| v as &str) == Some(module) { - outtypes.insert( - enum_.name, - outform::TypeInfo::Enum(outform::EnumInfo { + outtypes.insert(enum_.name.clone(), outform::TypeInfo { + name: enum_.name, + module: enum_.module.unwrap(), + details: outform::TypeDetails::Enum(outform::EnumInfo { description: enum_.description, details: enum_.details, variants: enum_ @@ -254,7 +259,7 @@ pub fn resolve_types( }) .collect(), }), - ); + }); } }