Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
"default": "",
"description": "Fill in with any valid MomentJs format (either explicit or locale) to include the date tag.\nFormats can include time as well.\nLeave empty to disable."
},
"jsdoc-generator.emptyLineAfterHeader": {
"type": "boolean",
"default": "true",
"description": "Add empty line after header (description, date, author)."
},
"jsdoc-generator.singleLineComments": {
"type": "boolean",
"default": "false",
"description": "Generate single line comments (/** ... */) instead of always multiple lines."
},
"jsdoc-generator.includeTypes": {
"type": "boolean",
"default": "true",
Expand Down
19 changes: 13 additions & 6 deletions src/JsdocBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ export class JsdocBuilder {
}
this.buildDate();
this.buildAuthor();
this.buildJsdocLine();
if (getConfig('emptyLineAfterHeader', true)) {
this.buildJsdocLine();
}
this.buildJsdocLine('constructor');
this.buildJsdocModifiers(node.modifiers);
await this.buildJsdocParameters(node.getFullText(), node.parameters);
Expand Down Expand Up @@ -455,7 +457,9 @@ export class JsdocBuilder {
}
this.buildDate();
this.buildAuthor();
this.buildJsdocLine();
if (getConfig('emptyLineAfterHeader', true)) {
this.buildJsdocLine();
}
}

/**
Expand All @@ -468,19 +472,19 @@ export class JsdocBuilder {
* @param {?NodeType} type
*/
private async buildDescription(nodeText?: string, description?: string, type?: NodeType) {
this.jsdoc.appendText(' * ');
const placeholder = getConfig('descriptionPlaceholder', '');
if (description) {
this.jsdoc.appendText(this.sanitize(description));
this.jsdoc.appendText(` * ${this.sanitize(description)}\n`);
} else if (placeholder) {
this.jsdoc.appendText(' * ');
this.jsdoc.appendPlaceholder(placeholder);
this.jsdoc.appendText('\n');
} else if (nodeText && type) {
const autoDescription = await GenerativeAPI.describeSnippet(nodeText, type);
if (autoDescription) {
this.jsdoc.appendText(this.sanitize(autoDescription));
this.jsdoc.appendText(` * ${this.sanitize(autoDescription)}\n`);
}
}
this.jsdoc.appendText('\n');
}

/**
Expand Down Expand Up @@ -538,6 +542,9 @@ export class JsdocBuilder {
if (this.jsdoc.value.startsWith('/**\n *\n') && (this.jsdoc.value.match(/\n/g) || []).length > 2) {
this.jsdoc.value = this.jsdoc.value.substring(0, 4) + this.jsdoc.value.substring(7);
}
if (getConfig("singleLineComments", false)) {
this.jsdoc.value = this.jsdoc.value.replace(/^\/\*\*\n \* ?(.*)\n$/, '/** $1');
}
this.jsdoc.appendText(' */\n');
}

Expand Down
12 changes: 12 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ interface Configuration {
* @type {string}
*/
dateFormat: string;
/**
* Empty line after header.
*
* @type {string}
*/
emptyLineAfterHeader: boolean;
/**
* Generate single line comments instead of always multiple lines.
*
* @type {boolean}
*/
singleLineComments: boolean;
/**
* Whether to include types in JSDocs.
*
Expand Down