Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Owning Type Arguments #714

Merged
merged 8 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ feature_tests/dotnet/Lib/** linguist-generated=true
feature_tests/js/api/** linguist-generated=true
feature_tests/js/docs/source/** linguist-generated=true
feature_tests/kotlin/somelib/** linguist-generated=true
feature_tests/js/api/** linguist-generated=true
feature_tests/js/api/** linguist-generated=true
feature_tests/demo_gen/demo/** linguist-generated=true
10 changes: 5 additions & 5 deletions feature_tests/demo_gen/demo/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions tool/src/demo_gen/terminus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct MethodDependency {

/// Parameters to pass into the method.
params: Vec<ParamInfo>,

/// The type name that this method belongs to. Currently used by [`OutParam`] for better default parameter names.
owning_type: String,
}

pub(super) struct RenderTerminusContext<'ctx, 'tcx> {
Expand All @@ -56,10 +59,11 @@ pub(super) struct RenderTerminusContext<'ctx, 'tcx> {
}

impl MethodDependency {
pub fn new(method_js: String) -> Self {
pub fn new(method_js: String, owning_type: String) -> Self {
MethodDependency {
method_js,
params: Vec::new(),
owning_type,
}
}
}
Expand Down Expand Up @@ -155,8 +159,10 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> {

// Not making this as part of the RenderTerminusContext because we want each evaluation to have a specific node,
// which I find easier easier to represent as a parameter to each function than something like an updating the current node in the struct.
let mut root =
MethodDependency::new(self.get_constructor_js(type_name.to_string(), method));
let mut root = MethodDependency::new(
self.get_constructor_js(type_name.clone(), method),
type_name.clone(),
);

// And then we just treat the terminus as a regular constructor method:
self.terminus_info.node_call_stack = self.evaluate_constructor(method, &mut root);
Expand Down Expand Up @@ -189,7 +195,12 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> {
let attrs_default = attrs.unwrap_or_default();
// This only works for enums, since otherwise we break the type into its component parts.
let label = if attrs_default.input_cfg.label.is_empty() {
heck::AsUpperCamelCase(param_name.clone()).to_string()
format!(
"{}:{}",
heck::AsUpperCamelCase(node.owning_type.clone()),
heck::AsUpperCamelCase(param_name.clone())
)
.to_string()
} else {
attrs_default.input_cfg.label
};
Expand Down Expand Up @@ -367,8 +378,10 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> {
self.relative_import_path.clone(),
));

let mut child =
MethodDependency::new(self.get_constructor_js(type_name.to_string(), method));
let mut child = MethodDependency::new(
self.get_constructor_js(type_name.to_string(), method),
type_name,
);

let call = self.evaluate_constructor(method, &mut child);
node.params.push(ParamInfo { js: call });
Expand Down Expand Up @@ -412,7 +425,7 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> {
self.relative_import_path.clone(),
));

let mut child = MethodDependency::new("".to_string());
let mut child = MethodDependency::new("".to_string(), type_name.clone());

#[derive(Template)]
#[template(path = "demo_gen/struct.js.jinja", escape = "none")]
Expand All @@ -430,7 +443,7 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> {
}

child.method_js = StructInfo {
type_name: type_name.to_string(),
type_name: type_name.clone(),
}
.render()
.unwrap();
Expand Down