Skip to content
Merged
Changes from all 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
35 changes: 28 additions & 7 deletions src/shared/seleneyamlgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,36 @@ class SeleneYamlBuilder {
prop.description = `OVERLOAD: ${func.comment}`;
}

const args: { type: SeleneArgDefType; count: number }[] = [];
const paramSets = overloads.map((overload) => overload.parameters);
paramSets.push(func.parameters);
// To handle overloads for now we count up the possible parameters to detemin required
// and try to check for matching parameter types, if we can't match them then use 'any'
const args: { type: SeleneArgDefType; count: number, optional: boolean}[] = [];
const paramSets = overloads.map((overload) => this.removeSelfFromParameters(overload.parameters));
paramSets.push(this.removeSelfFromParameters(func.parameters));
for (const params of paramSets) {
for (const i in params) {
const param = params[i];
const type =
this.generateFunctionArg(params[i], expand).type;
if (args[i]) {
const arg = args[i];
if (!argTypesEqual(type, arg.type)) {
arg.type = "any";
}
if(param.optional) arg.optional = true;
arg.count += 1;
} else args[i] = { type, count: 1 };
} else args[i] = { type, count: 1, optional:param.optional || false};
}
}
if (args.length) {
const max = args[0].count;
for (const arg of args) {
if (arg.count == max) prop.args.push({ type: arg.type });
else prop.args.push({ type: arg.type, required: false });
const param : SeleneArgDef = {
type: arg.type,
};
if(arg.count !== max || arg.optional) {
param.required = false;
}
prop.args.push(param);
}
}
return prop;
Expand All @@ -238,12 +247,22 @@ class SeleneYamlBuilder {
}
}

private removeSelfFromParameters(params: Parameter[]) : Parameter[] {
return params.filter(
(param,index) => {
return index != 0 || param.name !== "self"
}
);
}


private generateFunctionArgs(
func: FunctionSignature,
expand: boolean = false,
): SeleneArgDef[] {
const args: SeleneArgDef[] = [];
for (const param of func.parameters) {
const params = this.removeSelfFromParameters(func.parameters);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than creating a new array, I'd have checked the .name in the loop and just skipped it there.
Not a blocker

for (const param of params) {
const arg = this.generateFunctionArg(param, expand);
args.push(arg);
}
Expand Down Expand Up @@ -501,6 +520,8 @@ class SeleneYamlBuilder {
"any": "any",
"list": { display: "list" },
"{}": "table",
"false": "bool",
"true": "bool",
};

return typeMap[ref] ?? undefined;
Expand Down
Loading