Skip to content

Commit

Permalink
fix ctors and dtors
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Jan 12, 2025
1 parent 5537fd9 commit 183796e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/project/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ export class ModifyClassMethodCompletion implements CompletionItemProvider {
let suggestions = [];
for (let func of classInfo.functions) {
const shortFuncDecl = `${func.name}(${func.args.map((a) => `${a.type} ${a.name}`).join(", ")})`;
const fullFuncDecl = `${func.static ? "static " : ""}${func.return} ${shortFuncDecl}`;
const fullFuncDecl = `${func.static ? "static " : ""}${func.return} ${shortFuncDecl}`.trimStart();
const origCall = `${currentClass}::${func.name}(${func.args.map((a) => a.name).join(", ")})`;

let origStatement;
if (func.return === "void") {
origStatement = `\${1}\n\t${origCall};`;
} else if (func.return === "bool") {
origStatement = `if (!${origCall}) return false;\n\t\${1}\n\treturn true;`;
} else if (func.kind !== "normal") {
origStatement = `${origCall};\n\t\${1}`;
} else {
origStatement = `${func.return} ret = ${origCall};\n\t\${1}\n\treturn ret;`;
}
Expand All @@ -87,6 +89,9 @@ export class ModifyClassMethodCompletion implements CompletionItemProvider {
);

item.insertText = `${fullFuncDecl} {\n\t${origStatement}\n}`;
if (func.kind === "ctor" || func.kind === "dtor") {
item.insertText = `void ${func.kind === "ctor" ? "constructor" : "destructor"}() {\n\t${origStatement}\n}`;
}
if (stripCocos) {
item.insertText = item.insertText.replace(/cocos2d::/g, "");
}
Expand Down

0 comments on commit 183796e

Please sign in to comment.