From a036d378c03366009ad4a8dd64e3622d9dfe97af Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 21 Mar 2024 02:42:57 -0700 Subject: [PATCH] typegen: fix function and signal parameters being sorted by name --- layouts/partials/qmlparams.html | 6 +++--- typegen/src/outform.rs | 11 +++++++++-- typegen/src/resolver.rs | 15 +++++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/layouts/partials/qmlparams.html b/layouts/partials/qmlparams.html index 1135651..9445194 100644 --- a/layouts/partials/qmlparams.html +++ b/layouts/partials/qmlparams.html @@ -1,6 +1,6 @@ {{- $first := true -}} -{{- range $param, $type := . -}} +{{- range $param := . -}} {{- if ne $first true -}}, {{ end -}} {{- $first = false -}} - {{ $param }}: {{ partial "qmltype.html" $type }} -{{- end -}} \ No newline at end of file + {{ $param.name }}: {{ partial "qmltype.html" $param.type }} +{{- end -}} diff --git a/typegen/src/outform.rs b/typegen/src/outform.rs index a6012af..f893f56 100644 --- a/typegen/src/outform.rs +++ b/typegen/src/outform.rs @@ -52,14 +52,21 @@ pub struct Function { pub name: String, pub id: String, pub details: Option, - pub params: HashMap, + pub params: Vec, } #[derive(Debug, Serialize)] pub struct Signal { pub name: String, pub details: Option, - pub params: HashMap, + pub params: Vec, +} + +#[derive(Debug, Serialize)] +pub struct Parameter { + pub name: String, + #[serde(rename = "type")] + pub type_: Type, } #[derive(Debug, Serialize)] diff --git a/typegen/src/resolver.rs b/typegen/src/resolver.rs index f54de9f..7f7192f 100644 --- a/typegen/src/resolver.rs +++ b/typegen/src/resolver.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::{ - outform::{self, Flag, PropertyType}, + outform::{self, Flag, Parameter, PropertyType}, typespec::{FnParam, Function, Property, Signal, TypeSpec}, }; @@ -147,7 +147,8 @@ pub fn resolve_types( ret: qmlparamtype(&func.ret, typespec), name: func.name.clone(), id: { - let params = func.params + let params = func + .params .iter() .map(|FnParam { type_, .. }| qmlparamtype(type_, typespec).name); @@ -166,7 +167,10 @@ pub fn resolve_types( params: func .params .iter() - .map(|FnParam { type_, name }| (name.clone(), qmlparamtype(type_, typespec))) + .map(|FnParam { type_, name }| Parameter { + name: name.clone(), + type_: qmlparamtype(type_, typespec), + }) .collect(), } } @@ -178,7 +182,10 @@ pub fn resolve_types( params: func .params .iter() - .map(|FnParam { type_, name }| (name.clone(), qmlparamtype(type_, typespec))) + .map(|FnParam { type_, name }| Parameter { + name: name.clone(), + type_: qmlparamtype(type_, typespec), + }) .collect(), } }