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

new features #53

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.1.3 (2022/02/22)
* Added support to add in @author as a signature for a class
* Added an option for align the name of parameters of a method

## 1.1.2 (2020/06/10)
* Added support to add in @author, @copyright as a signature for a function.
* Also added in a feature for displaying date of creation of the comment. With location

## 1.1.1 (2020/06/10)
* Added support for functions that are not within a class

Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# PHPDoc Generator
# Note
This is a fork of the original [repo](https://github.com/ronvanderheijden/vscode-phpdoc-generator) and contains features of this other [fork](https://github.com/Samuel-Hinchliffe/vscode-phpdoc-generator.git)

I added this new features :
- Added support to add in @author as a signature for a class
- Added an option to align the name of parameters of a method
# A quick note
This is a fork of the original repo. All this app does is a few little things ontop. See the [original](https://marketplace.visualstudio.com/items?itemName=ronvanderheijden.phpdoc-generator) app and also checkout the github [repo](https://github.com/ronvanderheijden/vscode-phpdoc-generator) too.

[![Installs](https://img.shields.io/visual-studio-marketplace/v/ronvanderheijden.phpdoc-generator)](https://marketplace.visualstudio.com/items?itemName=ronvanderheijden.phpdoc-generator)
# What's new about this?
Now every function you generate can have a signature. You can have a @author signature for each function. You can @copyright for each function. Both with a @see signature so you can direct people towards a link. As well as having a snippet of code that will also display when the comment was generated.

![Screen Capture in Action](https://raw.githubusercontent.com/Samuel-Hinchliffe/vscode-phpdoc-generator/master/assets/example.png)
# PHPDoc Generator

PHPDoc Generator is [a VSCode extension](https://marketplace.visualstudio.com/items?itemName=ronvanderheijden.phpdoc-generator) that generates a PHP documentation block using a keyboard shortcut.

Expand Down
Binary file added assets/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 69 additions & 2 deletions lib/docBlockGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class DocBlockGenerator {
* @return {string}
*/
static generateClassDocBlock(doc) {
let author = config.get('author');
let docBlock = '/**\r\n';
docBlock += ` * [Description ${doc.getName()}]\r\n`;
if (author !== '') {
docBlock += ` *\r\n * @author ${author}\r\n`;
}
docBlock += ` */\r\n`;

return docBlock;
Expand Down Expand Up @@ -92,12 +96,15 @@ class DocBlockGenerator {
const shortType = config.get('shortType');
/** @var {boolean} indentAfterParameters */
const indentAfterParameters = config.get('insertIndentAfterParameters');
/** @var {boolean} alignParametersName */
const alignParametersName = config.get('alignParametersName');
/** @var {boolean|string} constructorWithType */
const constructorWithType = config.get('constructorWithType');
/** @var {string} indent */
const indent = doc.getIndent();

let docBlock = indent + '/**\r\n';
let space = ' ';

if (config.get('insertDescription')) {
docBlock += indent + ` * [Description for ${doc.getName()}]\r\n`;
Expand All @@ -115,14 +122,22 @@ class DocBlockGenerator {

/** @var {string[]} types */
let types;
let maxLen = 0;

for (let parameter of parameters) {
types = !shortType
? converter.convertTypes(parameter.types)
: parameter.types
;
parameter.strTypes = types.join('|');
maxLen = (parameter.strTypes.length > maxLen) ? parameter.strTypes.length : maxLen;
}

let strSpaces = '';

docBlock += indent + ` * @param ${types.join('|')} ${parameter.name}\r\n`;
for (let parameter of parameters) {
strSpaces = (alignParametersName) ? space.repeat(maxLen - parameter.strTypes.length) : '';
docBlock += indent + ` * @param ${parameter.strTypes} ${strSpaces}${parameter.name}\r\n`;
}
}

Expand All @@ -141,17 +156,69 @@ class DocBlockGenerator {
}

if (indentAfterParameters && doc.hasParameters() && typesOfMethod.length) {
docBlock += indent + ` * \r\n`;
docBlock += indent + ` *\r\n`;
}

if (typesOfMethod.length) {
docBlock += indent + ` * @return ${typesOfMethod.join('|')}\r\n`;
}

let alreadyAdded = false;
let maxLengthOtherTag = 0;
let strSpacesOther = '';

if (config.get('authorTag')) {
maxLengthOtherTag = "author".length
}
if (config.get('copyrightCompanyName')) {
maxLengthOtherTag = "copyright".length
}

if (config.get('displayCreationDate')) {
let currentTime = new Date().toLocaleString();
let timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
docBlock = DocBlockGenerator.addEmtyLineComment(docBlock, indent);
alreadyAdded = true;
docBlock += indent + ` * Created at: ${currentTime} (${timeZone})\r\n`;
}

if (config.get('authorTag')) {
docBlock = (!alreadyAdded) ? DocBlockGenerator.addEmtyLineComment(docBlock, indent) : docBlock;
alreadyAdded = true;
strSpacesOther = space.repeat(maxLengthOtherTag - "author".length);
docBlock += indent + ` * @author ${strSpacesOther}${config.get('authorTag')}\r\n`;
}

if (config.get('authorSeeUrl')) {
docBlock = (!alreadyAdded) ? DocBlockGenerator.addEmtyLineComment(docBlock, indent) : docBlock;
alreadyAdded = true;
strSpacesOther = space.repeat(maxLengthOtherTag - "see".length);
docBlock += indent + ` * @see ${strSpacesOther}{@link ${config.get('authorSeeUrl')}}\r\n`;
}

if (config.get('companySeeUrl')) {
docBlock = (!alreadyAdded) ? DocBlockGenerator.addEmtyLineComment(docBlock, indent) : docBlock;
alreadyAdded = true;
strSpacesOther = space.repeat(maxLengthOtherTag - "see".length);
docBlock += indent + ` * @see ${strSpacesOther}{@link ${config.get('companySeeUrl')}}\r\n`;
}

if (config.get('copyrightCompanyName')) {
docBlock = (!alreadyAdded) ? DocBlockGenerator.addEmtyLineComment(docBlock, indent) : docBlock;
alreadyAdded = true;
strSpacesOther = space.repeat(maxLengthOtherTag - "copyright".length);
docBlock += indent + ` * @copyright ${strSpacesOther}${config.get('copyrightCompanyName')}\r\n`;
}

docBlock += indent + ` */\r\n`;

return docBlock;
}

static addEmtyLineComment(docBlock, indent) {
const newEmptyLineComment = indent + ` *\r\n`;
return docBlock += newEmptyLineComment;
}
}

module.exports = DocBlockGenerator;
38 changes: 35 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "phpdoc-generator",
"displayName": "PHPDoc Generator",
"description": "PHPDoc Generator is a VSCode extension that generates a documentation block using a keyboard shortcut.",
"description": "PHPDoc Generator is a VSCode extension that generates a documentation block using a keyboard shortcut. Note: This is a fork of the original. Just with a few extra features. You can have a signature on every function for example",
"license": "MIT",
"author": {
"name": "Ron van der Heijden",
"email": "[email protected]"
},
"version": "1.1.1",
"version": "1.1.3",
"publisher": "ronvanderheijden",
"engines": {
"vscode": "^1.18.0"
Expand All @@ -18,6 +18,7 @@
],
"keywords": [
"php",
"php docs",
"phpdoc",
"phpdoc-generator",
"generator",
Expand All @@ -33,6 +34,11 @@
"configuration": {
"title": "PHPDoc Generator",
"properties": {
"phpdoc-generator.author": {
"type": "string",
"default": "",
"description": "Add's @author tag to class"
},
"phpdoc-generator.insertDescription": {
"type": "boolean",
"default": true,
Expand All @@ -43,6 +49,16 @@
"default": true,
"description": "Inserts the indent after parameters."
},
"phpdoc-generator.alignParametersName" : {
"type": "boolean",
"default": true,
"description": "Align the name of each parameter."
},
"phpdoc-generator.displayCreationDate" : {
"type": "boolean",
"default": false,
"description": "Displays Creation date on a method"
},
"phpdoc-generator.returnUndefinedType": {
"type": "string",
"default": "[type]",
Expand All @@ -64,6 +80,22 @@
],
"description": "Specifies the value of a type for @var when it is undefined."
},
"phpdoc-generator.authorTag": {
"type": "string",
"description": "Add's @author tag to the method"
},
"phpdoc-generator.authorSeeUrl": {
"type": "string",
"description": "Add's a @see tag to a url below the author tag for the method. For instance, @see https://github.com/"
},
"phpdoc-generator.companySeeUrl": {
"type": "string",
"description": "Add's a @see tag to a url near the copyright tag for the method. For instance, @see https://github.com/"
},
"phpdoc-generator.copyrightCompanyName": {
"type": "string",
"description": "Add's @copyright tag to the method"
},
"phpdoc-generator.shortType": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -126,7 +158,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/ronvanderheijden/vscode-phpdoc-generator.git"
"url": "https://github.com/Bruno86/vscode-phpdoc-generator.git"
},
"__metadata": {
"publisherDisplayName": "ronvanderheijden"
Expand Down