Skip to content

Commit

Permalink
Add descriptions to panel classes, structs
Browse files Browse the repository at this point in the history
Also trim description whitespace
  • Loading branch information
robotboy655 committed Feb 16, 2024
1 parent b3e3bd4 commit 9457527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/api-writer/glua-api-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ export class GluaApiWriter {
return this.writeStruct(page);
}

private writeClassStart(className: string, parent?: string, deprecated?: string) {
private writeClassStart(className: string, parent?: string, deprecated?: string, description?: string) {
let api: string = '';

if (!this.writtenClasses.has(className)) {
const classOverride = `class.${className}`;
if (this.pageOverrides.has(classOverride)) {
api += this.pageOverrides.get(classOverride)!.replace(/\n$/g, '') + '\n\n';
} else {
api += description ? `${putCommentBeforeEachLine(description, false)}\n` : '';

if (deprecated)
api += `---@deprecated ${removeNewlines(deprecated)}\n`
api += `---@deprecated ${removeNewlines(deprecated)}\n`;

api += `---@class ${className}`;

Expand Down Expand Up @@ -160,7 +162,7 @@ export class GluaApiWriter {
}

private writePanel(panel: Panel) {
let api: string = this.writeClassStart(panel.name, panel.parent, panel.deprecated);
let api: string = this.writeClassStart(panel.name, panel.parent, panel.deprecated, panel.description);

return api;
}
Expand All @@ -185,7 +187,7 @@ export class GluaApiWriter {

if (isContainedInTable)
{
api += _enum.description ? `${putCommentBeforeEachLine(_enum.description, false)}\n` : ''
api += _enum.description ? `${putCommentBeforeEachLine(_enum.description, false)}\n` : '';
api += `${_enum.name} = {\n`;
}

Expand All @@ -194,7 +196,7 @@ export class GluaApiWriter {
key = key.split('.')[1];
api += ` ${key} = ${item.value}, ` + (item.description ? `--[[ ${item.description} ]]` : '') + '\n';
} else {
api += item.description ? `${putCommentBeforeEachLine(item.description, false)}\n` : ''
api += item.description ? `${putCommentBeforeEachLine(item.description, false)}\n` : '';
if (item.deprecated)
api += `---@deprecated ${removeNewlines(item.deprecated)}\n`;
api += `${key} = ${item.value}\n`;
Expand Down Expand Up @@ -223,7 +225,7 @@ export class GluaApiWriter {
}

private writeStruct(struct: Struct) {
let api: string = this.writeClassStart(struct.name, undefined, struct.deprecated);
let api: string = this.writeClassStart(struct.name, undefined, struct.deprecated, struct.description);

for (const field of struct.fields) {
if (field.deprecated)
Expand All @@ -232,7 +234,7 @@ export class GluaApiWriter {
api += `---${removeNewlines(field.description).replace(/\s+/g, ' ')}\n`;

const type = this.transformType(field.type)
api += `---@type ${type}\n`
api += `---@type ${type}\n`;
api += `${struct.name}.${GluaApiWriter.safeName(field.name)} = ${field.default ? this.writeType(type, field.default) : 'nil'}\n\n`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function putCommentBeforeEachLine(text: string, skipLineOne: boolean = tr
return line;

let space = line.length > 0 ? ' ' : '';
return `---${space}${line}`;
return `---${space}${line.trimEnd()}`;
}).join('\n');
}

Expand Down

0 comments on commit 9457527

Please sign in to comment.