2
1
Fork 0

typegen: further reference shorthand for members of current class

This commit is contained in:
outfoxxed 2024-07-21 15:38:01 -07:00
parent 1f47b15963
commit 1fc815f73e
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 73 additions and 47 deletions

View file

@ -1,7 +1,7 @@
{{- if eq .type "unknown" -}} {{- if eq .type "unknown" -}}
unknown unknown
{{- else -}} {{- else -}}
{{- $link := "#ERROR" -}} {{- $link := "" -}}
{{- if eq .type "qt" -}} {{- if eq .type "qt" -}}
{{- $link = printf "https://doc.qt.io/qt-6/%s-%s.html" (lower (replace .module "." "-")) (lower .name) -}} {{- $link = printf "https://doc.qt.io/qt-6/%s-%s.html" (lower (replace .module "." "-")) (lower .name) -}}
{{- else if eq .type "local" -}} {{- else if eq .type "local" -}}
@ -13,30 +13,39 @@
{{- $of = printf "<%s>" (partial "qmltype.html" .of) }} {{- $of = printf "<%s>" (partial "qmltype.html" .of) }}
{{- end -}} {{- end -}}
{{- $prefix := "" -}}
{{- $member := "" -}} {{- $member := "" -}}
{{- if .prop -}} {{- if .mtype -}}
{{- $member = printf ".%s" .prop -}} {{- if .type -}}
{{- if eq .type "qt" -}} {{- $member = printf ".%s" .mname -}}
{{- $link = printf "%s#%s-prop" $link .prop -}} {{- else -}}
{{- else if eq .type "local" -}} {{- $member = .mname -}}
{{- $link = printf "%s#prop.%s" $link .prop -}}
{{- end -}} {{- end -}}
{{- else if .func -}}
{{- $member = printf ".%s()" .func -}} {{- if eq .mtype "prop" -}}
{{- if eq .type "qt" -}} {{- if eq .type "qt" -}}
{{- $link = printf "%s#%s-method" $link .func -}} {{- $link = printf "%s#%s-prop" $link .mname -}}
{{- else if eq .type "local" -}} {{- else -}}
{{- $link = printf "%s#func.%s" $link .func -}} {{- $link = printf "%s#prop.%s" $link .mname -}}
{{- end -}} {{- end -}}
{{- else if .signal -}} {{- else if eq .mtype "func" -}}
{{- $member = printf ".%s()" .signal -}} {{- $member = printf "%s()" $member -}}
{{- if eq .type "qt" -}} {{- if eq .type "qt" -}}
{{- $link = printf "%s#%s-signal" $link .signal -}} {{- $link = printf "%s#%s-method" $link .mname -}}
{{- else if eq .type "local" -}} {{- else -}}
{{- $link = printf "%s#signal.%s" $link .signal -}} {{- $link = printf "%s#func.%s" $link .mname -}}
{{- end -}}
{{- else if eq .mtype "signal" -}}
{{- $prefix = "[signal] " -}}
{{- $member = printf "%s()" $member -}}
{{- if eq .type "qt" -}}
{{- $link = printf "%s#%s-signal" $link .mname -}}
{{- else -}}
{{- $link = printf "%s#signal.%s" $link .mname -}}
{{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
<a href="{{ $link }}">{{ .name }}{{ $member }}</a>{{ $of | safeHTML -}} <a href="{{ $link }}">{{ $prefix }}{{ .name }}{{ $member }}</a>{{ $of | safeHTML -}}
{{- end -}} {{- end -}}

View file

@ -663,45 +663,62 @@ fn parse_details(comment: Comment) -> String {
}) })
.unwrap_or_else(|| (src.len(), src)); .unwrap_or_else(|| (src.len(), src));
let mut split = ty.rsplit_once('.').unwrap_or(("", ty));
let member = split
.1
.chars()
.next()
.unwrap()
.is_lowercase()
.then(|| {
let prop = split.1;
split = split.0.rsplit_once('.').unwrap_or(("", split.0));
prop
})
.unwrap_or("");
// special case for . as it is contained in valid types as well // special case for . as it is contained in valid types as well
if ty.ends_with('.') { if ty.ends_with('.') {
end -= 1; end -= 1;
ty = &ty[..ty.len() - 1]; ty = &ty[..ty.len() - 1];
} }
let (prop, func, signal) = match member { let (ty, member) = match ty.chars().next() {
name if name.ends_with("()") => ("", &name[..name.len() - 2], ""), None => (None, None),
name if name.ends_with("(s)") => ("", "", &name[..name.len() - 3]), Some(c) if c.is_lowercase() => (None, Some(ty)),
name => (name, "", ""), Some(_) => {
let mut split = ty.rsplit_once('.').unwrap_or(("", ty));
let member = split
.1
.chars()
.next()
.unwrap()
.is_lowercase()
.then(|| {
let prop = split.1;
split = split.0.rsplit_once('.').unwrap_or(("", split.0));
prop
})
.unwrap_or("");
let (mut module, name) = split;
if module.is_empty() {
module = comment.module;
}
(Some((module, name)), Some(member))
},
}; };
let (mut module, name) = split; let (membertype, membername) = match member {
None => ("", ""),
Some(name) if name.ends_with("()") => ("func", &name[..name.len() - 2]),
Some(name) if name.ends_with("(s)") => ("signal", &name[..name.len() - 3]),
Some(name) => ("prop", name),
};
if module.is_empty() { let ((linktype, module), name) = match ty {
module = comment.module; Some((module, name)) => {
} let module = match module {
module if module.starts_with("Quickshell") => ("local", module.to_string()),
module => ("qt", format!("qml.{module}")),
};
let (linktype, module) = match module.starts_with("Quickshell") { (module, name)
true => ("local", module.to_string()), },
false => ("qt", format!("qml.{module}")), None => (("", String::new()), ""),
}; };
accum += &format!( accum += &format!(
r#"{{{{< qmltypelink type="{linktype}" module="{module}" name="{name}" prop="{prop}" func="{func}" signal="{signal}" >}}}}"# r#"{{{{< qmltypelink type="{linktype}" module="{module}" name="{name}" mtype="{membertype}" mname="{membername}" >}}}}"#
); );
src = &src[end..]; src = &src[end..];
} }