Skip to content

Commit

Permalink
Merge pull request #78 from neild3r/return-gap
Browse files Browse the repository at this point in the history
Allow gap between return and params
  • Loading branch information
neild3r committed Mar 24, 2018
2 parents 18eb459 + bd626f4 commit 94d9fab
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This extension has no dependencies.
This extension contributes the following settings:

* `php-docblocker.gap`: set to `false` to disable the gap between the description and tags
* `php-docblocker.returnGap`: set to `true` to add a gap between the param and return tags
* `php-docblocker.extra`: an array of extra tags to add to each DocBlock (These can include tabstops and snippet variables)
* `php-docblocker.useShortNames`: Whether we should use short type names. e.g. bool or boolean

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"default": true,
"description": "If there should be a gap between the description and tags"
},
"php-docblocker.returnGap": {
"type": "boolean",
"default": false,
"description": "If there should be a gap between params and return"
},
"php-docblocker.extra": {
"type": "array",
"default": [],
Expand Down
8 changes: 7 additions & 1 deletion src/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class Doc
let snippet = new SnippetString();
let extra = this.getConfig().extra;
let gap = !this.getConfig().gap;
let returnGap = this.getConfig().returnGap;

if (isEmpty) {
gap = true;
Expand Down Expand Up @@ -148,6 +149,8 @@ export class Doc
if (!gap) {
snippet.appendText("\n *");
gap = true;
} else if (returnGap && this.params.length) {
snippet.appendText("\n *");
}
snippet.appendText("\n * @return ");
snippet.appendVariable(stop++ + '', this.return);
Expand All @@ -160,7 +163,10 @@ export class Doc
}
for (var index = 0; index < extra.length; index++) {
var element = extra[index];
snippet.appendText("\n * ");
if (element != "") {
element = " " + element;
}
snippet.appendText("\n *");
snippet.value += element;
}
}
Expand Down
54 changes: 54 additions & 0 deletions test/fixtures/doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,59 @@
" * @param ${2:int} ${3:\\$name}",
" */"
]
},
{
"name": "Empty extra string",
"config": {
"gap": true,
"extra": [
"",
"@author John Smith <john@smith.com>"
]
},
"input": {
"message": "Undocumented function",
"params": [
{
"name": "$name",
"type": "int"
}
]
},
"expected": [
"/**",
" * ${1:Undocumented function}",
" *",
" * @param ${2:int} ${3:\\$name}",
" *",
" * @author John Smith <john@smith.com>",
" */"
]
},
{
"name": "Return gap",
"config": {
"gap": true,
"returnGap": true
},
"input": {
"message": "Undocumented function",
"params": [
{
"name": "$name",
"type": "int"
}
],
"return": "void"
},
"expected": [
"/**",
" * ${1:Undocumented function}",
" *",
" * @param ${2:int} ${3:\\$name}",
" *",
" * @return ${4:void}",
" */"
]
}
]

0 comments on commit 94d9fab

Please sign in to comment.