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,37 +211,42 @@ pub fn resolve_types(
None => HashMap::new(), None => HashMap::new(),
}; };
let type_ = outform::ClassInfo { let type_ = outform::TypeInfo {
superclass, name: mapping.name.clone(),
description: class.description.clone(), module: mapping.module.clone().unwrap(),
details: class.details.clone(), details: outform::TypeDetails::Class(outform::ClassInfo {
flags: { superclass,
let mut flags = Vec::new(); description: class.description.clone(),
details: class.details.clone(),
flags: {
let mut flags = Vec::new();
if coreenum.is_some() { if coreenum.is_some() {
flags.push(Flag::Enum); flags.push(Flag::Enum);
} else if class.singleton { } else if class.singleton {
flags.push(Flag::Singleton); flags.push(Flag::Singleton);
} else if class.uncreatable { } else if class.uncreatable {
flags.push(Flag::Uncreatable); flags.push(Flag::Uncreatable);
} }
flags flags
}, },
properties, properties,
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(),
}), }),
); });
} }
} }