From 3fe7cf9bf980208b7ceb581073fed01602efc54b Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sat, 20 Jul 2024 02:18:06 -0700 Subject: [PATCH] typegen: add reference shorthand for functions and signals --- layouts/partials/qmltype.html | 14 ++++++++++++++ typegen/src/parse.rs | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/layouts/partials/qmltype.html b/layouts/partials/qmltype.html index 2686d78..d5a923c 100644 --- a/layouts/partials/qmltype.html +++ b/layouts/partials/qmltype.html @@ -22,6 +22,20 @@ {{- else if eq .type "local" -}} {{- $link = printf "%s#prop.%s" $link .prop -}} {{- end -}} + {{- else if .func -}} + {{- $member = printf ".%s()" .func -}} + {{- if eq .type "qt" -}} + {{- $link = printf "%s#%s-method" $link .func -}} + {{- else if eq .type "local" -}} + {{- $link = printf "%s#func.%s" $link .func -}} + {{- end -}} + {{- else if .signal -}} + {{- $member = printf ".%s()" .signal -}} + {{- if eq .type "qt" -}} + {{- $link = printf "%s#%s-signal" $link .signal -}} + {{- else if eq .type "local" -}} + {{- $link = printf "%s#signal.%s" $link .signal -}} + {{- end -}} {{- end -}} {{ .name }}{{ $member }}{{ $of | safeHTML -}} diff --git a/typegen/src/parse.rs b/typegen/src/parse.rs index 9f4e586..d52a29f 100644 --- a/typegen/src/parse.rs +++ b/typegen/src/parse.rs @@ -658,7 +658,7 @@ fn parse_details(comment: Comment) -> String { let mut split = ty.rsplit_once('.').unwrap_or(("", ty)); - let prop = split + let member = split .1 .chars() .next() @@ -671,6 +671,12 @@ fn parse_details(comment: Comment) -> String { }) .unwrap_or(""); + let (prop, func, signal) = match member { + name if name.ends_with("()") => ("", &name[..name.len() - 2], ""), + name if name.ends_with("(s)") => ("", "", &name[..name.len() - 3]), + name => (name, "", ""), + }; + let (mut module, name) = split; if module.is_empty() { @@ -683,7 +689,7 @@ fn parse_details(comment: Comment) -> String { }; accum += &format!( - r#"{{{{< qmltypelink type="{linktype}" module="{module}" name="{name}" prop="{prop}" >}}}}"# + r#"{{{{< qmltypelink type="{linktype}" module="{module}" name="{name}" prop="{prop}" func="{func}" signal="{signal}" >}}}}"# ); src = &src[end..]; }