2
1
Fork 0

typegen: add module and name fields to type files

This commit is contained in:
outfoxxed 2024-07-22 15:24:43 -07:00
parent b78b75f006
commit 997eb9e876
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 38 additions and 25 deletions

View file

@ -9,10 +9,18 @@ pub struct ModuleIndex {
pub details: String, pub details: String,
} }
#[derive(Debug, Serialize)]
pub struct TypeInfo {
pub name: String,
pub module: String,
#[serde(flatten)]
pub details: TypeDetails,
}
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
#[serde(tag = "type")] #[serde(tag = "type")]
pub enum TypeInfo { pub enum TypeDetails {
Class(ClassInfo), Class(ClassInfo),
Enum(EnumInfo), Enum(EnumInfo),
} }

View file

@ -211,7 +211,10 @@ pub fn resolve_types(
None => HashMap::new(), None => HashMap::new(),
}; };
let type_ = outform::ClassInfo { let type_ = outform::TypeInfo {
name: mapping.name.clone(),
module: mapping.module.clone().unwrap(),
details: outform::TypeDetails::Class(outform::ClassInfo {
superclass, superclass,
description: class.description.clone(), description: class.description.clone(),
details: class.details.clone(), details: class.details.clone(),
@ -232,16 +235,18 @@ pub fn resolve_types(
functions, functions,
signals, signals,
variants, variants,
}),
}; };
outtypes.insert(mapping.name.clone(), outform::TypeInfo::Class(type_)); outtypes.insert(mapping.name.clone(), type_);
} }
for enum_ in typespec.enums { for enum_ in typespec.enums {
if enum_.module.as_ref().map(|v| v as &str) == Some(module) { if enum_.module.as_ref().map(|v| v as &str) == Some(module) {
outtypes.insert( outtypes.insert(enum_.name.clone(), outform::TypeInfo {
enum_.name, name: enum_.name,
outform::TypeInfo::Enum(outform::EnumInfo { module: enum_.module.unwrap(),
details: outform::TypeDetails::Enum(outform::EnumInfo {
description: enum_.description, description: enum_.description,
details: enum_.details, details: enum_.details,
variants: enum_ variants: enum_
@ -254,7 +259,7 @@ pub fn resolve_types(
}) })
.collect(), .collect(),
}), }),
); });
} }
} }