summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2018-02-24 23:29:59 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-02-25 01:58:38 +0100
commit041439c5544ca8f9627a922e125dbf7e7ad11769 (patch)
tree9e3047bd1a3f40d1e2de02e5a736c26ad3980e68
parentf928a1049c6582e2fbb044676c5bbca89d9b7e33 (diff)
downloaddoxdocgen-041439c5544ca8f9627a922e125dbf7e7ad11769.tar.gz
Add options and allow change of option order
-rw-r--r--package.json288
-rw-r--r--src/Config.ts7
-rw-r--r--src/Lang/Cpp/CppDocGen.ts95
-rw-r--r--src/test/CppTests/Config.test.ts7
-rw-r--r--src/test/CppTests/TestSetup.ts8
-rw-r--r--src/test/tools/MockDocument.ts1
6 files changed, 238 insertions, 168 deletions
diff --git a/package.json b/package.json
index d19ff9e..5b6379c 100644
--- a/package.json
+++ b/package.json
@@ -1,139 +1,155 @@
{
- "name": "doxdocgen",
- "displayName": "Doxygen Documentation Generator",
- "description": "Generate doxygen documentation from source code",
- "version": "0.1.0",
- "publisher": "cschlosser",
- "engines": {
- "vscode": "^1.16.0"
- },
- "categories": [
- "Other"
- ],
- "activationEvents": [
- "onLanguage:cpp",
- "onLanguage:c"
- ],
- "contributes": {
- "configuration": {
- "type": "object",
- "title": "Doxygen Documentation Generator Settings",
- "properties": {
- "doxdocgen.generic.triggerSequence": {
- "description": "Doxygen comment trigger. This character sequence triggers generation of DoxyGen comments.",
- "type": "string",
- "default": "/**"
- },
- "doxdocgen.generic.firstLine": {
- "description": "The first line of the comment that gets generated. If empty it won't get generated at all.",
- "type": "string",
- "default": "/**"
- },
- "doxdocgen.generic.commentPrefix": {
- "description": "The prefix that is used for each comment line.",
- "type": "string",
- "default": " * "
- },
- "doxdocgen.generic.lastLine": {
- "description": "The last line of the comment that gets generated. If empty it won't get generated at all.",
- "type": "string",
- "default": " */"
- },
- "doxdocgen.generic.newLineAfterBrief": {
- "description": "Whether to insert a newline after a brief.",
- "type": "boolean",
- "default": true
- },
- "doxdocgen.generic.newLineAfterParams": {
- "description": "Whether to insert a newline after the params.",
- "type": "boolean",
- "default": false
- },
- "doxdocgen.generic.newLineAfterTParams": {
- "description": "Whether to insert a newline after the template params.",
- "type": "boolean",
- "default": false
- },
- "doxdocgen.generic.includeTypeAtReturn": {
- "description": "Whether include type information at return.",
- "type": "boolean",
- "default": true
- },
- "doxdocgen.generic.boolReturnsTrueFalse": {
- "description": "If this is enabled a bool return value will be split into true and false return param.",
- "type": "boolean",
- "default": true
- },
- "doxdocgen.generic.briefTemplate": {
- "description": "The template of the brief DoxyGen line that is generated. If empty it won't get generated at all.",
- "type": "string",
- "default": "@brief "
- },
- "doxdocgen.generic.paramTemplate": {
- "description": "The template of the param DoxyGen line(s) that are generated. If empty it won't get generated at all.",
- "type": "string",
- "default": "@param {param} "
- },
- "doxdocgen.generic.tparamTemplate": {
- "description": "The template of the template parameter DoxyGen line(s) that are generated. If empty it won't get generated at all.",
- "type": "string",
- "default": "@tparam {param} "
- },
- "doxdocgen.generic.returnTemplate": {
- "description": "The template of the return DoxyGen line that is generated. If empty it won't get generated at all.",
- "type": "string",
- "default": "@return {type} "
- },
- "doxdocgen.generic.linesToGet": {
- "description": "How many lines the plugin should look for to find the end of the declaration. Please be aware that setting this value too low may improve the speed of comment generation but the plugin also may not correctly detect all declarations or definitions anymore.",
- "type": "number",
- "default": 20
- },
- "doxdocgen.file.author": {
- "description": "Set the style of the author tag and your name.",
- "type": "string",
- "default": "@author your name"
- },
- "doxdocgen.file.file": {
- "description": "The template for the file parameter in DoxyGen.",
- "type": "string",
- "default": "@file {name}"
- }
- }
+ "name": "doxdocgen",
+ "displayName": "Doxygen Documentation Generator",
+ "description": "Generate doxygen documentation from source code",
+ "version": "0.1.0",
+ "publisher": "cschlosser",
+ "engines": {
+ "vscode": "^1.16.0"
+ },
+ "categories": [
+ "Other"
+ ],
+ "activationEvents": [
+ "onLanguage:cpp",
+ "onLanguage:c"
+ ],
+ "contributes": {
+ "configuration": {
+ "type": "object",
+ "title": "Doxygen Documentation Generator Settings",
+ "properties": {
+ "doxdocgen.generic.triggerSequence": {
+ "description": "Doxygen comment trigger. This character sequence triggers generation of DoxyGen comments.",
+ "type": "string",
+ "default": "/**"
+ },
+ "doxdocgen.generic.firstLine": {
+ "description": "The first line of the comment that gets generated. If empty it won't get generated at all.",
+ "type": "string",
+ "default": "/**"
+ },
+ "doxdocgen.generic.commentPrefix": {
+ "description": "The prefix that is used for each comment line.",
+ "type": "string",
+ "default": " * "
+ },
+ "doxdocgen.generic.lastLine": {
+ "description": "The last line of the comment that gets generated. If empty it won't get generated at all.",
+ "type": "string",
+ "default": " */"
+ },
+ "doxdocgen.generic.newLineAfterBrief": {
+ "description": "Whether to insert a newline after a brief.",
+ "type": "boolean",
+ "default": true
+ },
+ "doxdocgen.generic.newLineAfterParams": {
+ "description": "Whether to insert a newline after the params.",
+ "type": "boolean",
+ "default": false
+ },
+ "doxdocgen.generic.newLineAfterTParams": {
+ "description": "Whether to insert a newline after the template params.",
+ "type": "boolean",
+ "default": false
+ },
+ "doxdocgen.generic.includeTypeAtReturn": {
+ "description": "Whether include type information at return.",
+ "type": "boolean",
+ "default": true
+ },
+ "doxdocgen.generic.boolReturnsTrueFalse": {
+ "description": "If this is enabled a bool return value will be split into true and false return param.",
+ "type": "boolean",
+ "default": true
+ },
+ "doxdocgen.generic.briefTemplate": {
+ "description": "The template of the brief DoxyGen line that is generated. If empty it won't get generated at all.",
+ "type": "string",
+ "default": "@brief "
+ },
+ "doxdocgen.generic.paramTemplate": {
+ "description": "The template of the param DoxyGen line(s) that are generated. If empty it won't get generated at all.",
+ "type": "string",
+ "default": "@param {param} "
+ },
+ "doxdocgen.generic.tparamTemplate": {
+ "description": "The template of the template parameter DoxyGen line(s) that are generated. If empty it won't get generated at all.",
+ "type": "string",
+ "default": "@tparam {param} "
+ },
+ "doxdocgen.generic.returnTemplate": {
+ "description": "The template of the return DoxyGen line that is generated. If empty it won't get generated at all.",
+ "type": "string",
+ "default": "@return {type} "
+ },
+ "doxdocgen.generic.linesToGet": {
+ "description": "How many lines the plugin should look for to find the end of the declaration. Please be aware that setting this value too low may improve the speed of comment generation but the plugin also may not correctly detect all declarations or definitions anymore.",
+ "type": "number",
+ "default": 20
+ },
+ "doxdocgen.generic.authorTag": {
+ "description": "Set the style of the author tag and your name.",
+ "type": "string",
+ "default": "@author your name"
+ },
+ "doxdocgen.generic.fileTemplate": {
+ "description": "The template for the file parameter in DoxyGen.",
+ "type": "string",
+ "default": "@file {name}"
+ },
+ "doxdocgen.generic.dateTemplate": {
+ "description": "The template for the date parameter in DoxyGen.",
+ "type": "string",
+ "default": "@date {date}"
+ },
+ "doxdocgen.generic.dateFormat": {
+ "description": "The format to use for the date.",
+ "type": "string",
+ "default": "YYYY-MM-DD"
+ },
+ "doxdocgen.generic.fileOrder": {
+ "description": "The order to use for the date. Valid values are shown in default setting.",
+ "type": ["array", "string"],
+ "default": ["brief", "file", "author", "date"]
}
- },
- "icon": "images/icon.png",
- "keywords": [
- "cpp",
- "c++",
- "c",
- "doxygen"
- ],
- "license": "SEE LICENSE IN LICENSE",
- "main": "./out/extension",
- "repository": {
- "type": "git",
- "url": "https://github.com/christophschlosser/doxdocgen.git"
- },
- "bugs": {
- "url": "https://github.com/christophschlosser/doxdocgen/issues"
- },
- "scripts": {
- "vscode:prepublish": "npm run compile",
- "compile": "tsc -p ./",
- "watch": "tsc -watch -p ./",
- "postinstall": "node ./node_modules/vscode/bin/install",
- "test": "npm run compile && node ./node_modules/vscode/bin/test"
- },
- "devDependencies": {
- "typescript": "^2.7.2",
- "vscode": "^1.1.10",
- "@types/node": "^7.0.43",
- "@types/mocha": "^2.2.48",
- "tslint": "^5.9.1",
- "istanbul": "^0.4.5",
- "mocha": "^5.0.1",
- "remap-istanbul": "^0.10.1",
- "decache": "^4.4.0"
+ }
}
-} \ No newline at end of file
+ },
+ "icon": "images/icon.png",
+ "keywords": [
+ "cpp",
+ "c++",
+ "c",
+ "doxygen"
+ ],
+ "license": "SEE LICENSE IN LICENSE",
+ "main": "./out/extension",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/christophschlosser/doxdocgen.git"
+ },
+ "bugs": {
+ "url": "https://github.com/christophschlosser/doxdocgen/issues"
+ },
+ "scripts": {
+ "vscode:prepublish": "npm run compile",
+ "compile": "tsc -p ./",
+ "watch": "tsc -watch -p ./",
+ "postinstall": "node ./node_modules/vscode/bin/install",
+ "test": "npm run compile && node ./node_modules/vscode/bin/test"
+ },
+ "devDependencies": {
+ "@types/mocha": "^2.2.48",
+ "@types/node": "^7.0.43",
+ "decache": "^4.4.0",
+ "istanbul": "^0.4.5",
+ "mocha": "^5.0.1",
+ "moment": "^2.20.1",
+ "remap-istanbul": "^0.10.1",
+ "tslint": "^5.9.1",
+ "typescript": "^2.7.2",
+ "vscode": "^1.1.10"
+ }
+}
diff --git a/src/Config.ts b/src/Config.ts
index 9b86fc8..e8d7379 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -22,6 +22,9 @@ export class Config {
values.linesToGet = cfg.get<number>("linesToGet", values.linesToGet);
values.authorTag = cfg.get<string>("authorTag", values.authorTag);
values.fileTemplate = cfg.get<string>("fileTemplate", values.fileTemplate);
+ values.dateTemplate = cfg.get<string>("dateTemplate", values.dateTemplate);
+ values.dateFormat = cfg.get<string>("dateFormat", values.dateFormat);
+ values.fileOrder = cfg.get<string[]>("fileOrder", values.fileOrder);
return values;
}
@@ -29,6 +32,7 @@ export class Config {
public readonly paramTemplateReplace: string = "{param}";
public readonly typeTemplateReplace: string = "{type}";
public readonly nameTemplateReplace: string = "{name}";
+ public readonly dateTemplateReplace: string = "{date}";
public triggerSequence: string = "/**";
public firstLine: string = "/**";
@@ -46,4 +50,7 @@ export class Config {
public linesToGet: number = 20;
public authorTag: string = "@author your name";
public fileTemplate: string = "@file {name}";
+ public dateTemplate: string = "@date {date}";
+ public dateFormat: string = "YYYY-MM-DD";
+ public fileOrder: string[] = ["brief", "file", "author", "date"];
}
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index 83803cd..ebfa5f5 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -1,3 +1,4 @@
+import * as moment from "moment";
import { Position, Range, Selection, TextEditor, TextLine, WorkspaceEdit } from "vscode";
import { IDocGen } from "../../Common/IDocGen";
import { Config } from "../../Config";
@@ -115,35 +116,86 @@ export default class CppDocGen implements IDocGen {
return params;
}
- protected generateFileDescription(): string {
- const lines: string[] = [];
+ protected generateAuthorTag(lines: string[]) {
+ if (this.cfg.authorTag.trim().length !== 0) {
+ lines.push(this.cfg.commentPrefix + this.cfg.authorTag);
+ }
+ }
+ protected generateFilenameFromTemplate(lines: string[]) {
+ if (this.cfg.fileTemplate.trim().length !== 0) {
+ this.generateFromTemplate(
+ lines,
+ this.cfg.nameTemplateReplace,
+ this.cfg.fileTemplate,
+ [this.activeEditor.document.fileName.replace(/^.*[\\\/]/, "")],
+ );
+ }
+ }
+
+ protected generateDateFromTemplate(lines: string[]) {
+ if (this.cfg.dateTemplate.trim().length !== 0 &&
+ this.cfg.dateFormat.trim().length !== 0) {
+ this.generateFromTemplate(
+ lines,
+ this.cfg.dateTemplateReplace,
+ this.cfg.dateTemplate,
+ [moment().format(this.cfg.dateFormat)],
+ );
+ }
+ }
+
+ protected insertFirstLine(lines: string[]) {
if (this.cfg.firstLine.trim().length !== 0) {
lines.push(this.cfg.firstLine);
}
+ }
+ protected insertBrief(lines: string[]) {
if (this.cfg.briefTemplate.trim().length !== 0) {
this.generateBrief(lines);
if (this.cfg.newLineAfterBrief === true) {
lines.push(this.cfg.commentPrefix);
}
}
+ }
- lines.push(this.cfg.commentPrefix + this.cfg.authorTag);
-
- this.generateFromTemplate(
- lines,
- this.cfg.nameTemplateReplace,
- this.cfg.fileTemplate,
- [this.activeEditor.document.fileName.replace(/^.*[\\\/]/, "")],
- );
-
- // todo add date to file creation
- // lines.push(new Date().toLocaleDateString());
-
+ protected insertLastLine(lines: string[]) {
if (this.cfg.lastLine.trim().length !== 0) {
lines.push(this.cfg.lastLine);
}
+ }
+
+ protected generateFileDescription(): string {
+ const lines: string[] = [];
+
+ this.insertFirstLine(lines);
+
+ this.cfg.fileOrder.forEach((element) => {
+ switch (element) {
+ case "brief": {
+ this.insertBrief(lines);
+ break;
+ }
+ case "file": {
+ this.generateFilenameFromTemplate(lines);
+ break;
+ }
+ case "author": {
+ this.generateAuthorTag(lines);
+ break;
+ }
+ case "date": {
+ this.generateDateFromTemplate(lines);
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ });
+
+ this.insertLastLine(lines);
return lines.join("\n");
}
@@ -151,16 +203,9 @@ export default class CppDocGen implements IDocGen {
protected generateComment(): string {
const lines: string[] = [];
- if (this.cfg.firstLine.trim().length !== 0) {
- lines.push(this.cfg.firstLine);
- }
+ this.insertFirstLine(lines);
- if (this.cfg.briefTemplate.trim().length !== 0) {
- this.generateBrief(lines);
- if (this.cfg.newLineAfterBrief === true) {
- lines.push(this.cfg.commentPrefix);
- }
- }
+ this.insertBrief(lines);
if (this.cfg.tparamTemplate.trim().length !== 0 && this.templateParams.length > 0) {
this.generateFromTemplate(
@@ -187,9 +232,7 @@ export default class CppDocGen implements IDocGen {
this.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.returnTemplate, returnParams);
}
- if (this.cfg.lastLine.trim().length !== 0) {
- lines.push(this.cfg.lastLine);
- }
+ this.insertLastLine(lines);
const comment: string = lines.join("\n" + this.getIndentation());
return comment;
diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts
index 8a8e939..0459dcb 100644
--- a/src/test/CppTests/Config.test.ts
+++ b/src/test/CppTests/Config.test.ts
@@ -83,12 +83,13 @@ suite("C++ - Configuration Tests", () => {
test("Lines to get test", () => {
testSetup.cfg = new Config();
- testSetup.cfg.linesToGet = 1;
- const negativeResult = testSetup.SetLines(["template<typename T> bool \n", "foo(T a);"]).GetResult();
- assert.equal("/**\n * @brief \n * \n */", negativeResult);
testSetup.cfg.linesToGet = 2;
const positiveResult = testSetup.SetLines(["template<typename T> bool \n", "foo(T a);"]).GetResult();
assert.equal("/**\n * @brief \n * \n * @tparam T \n * @param a \n * "
+ "@return true \n * @return false \n */", positiveResult);
+ testSetup.cfg.linesToGet = 0;
+ testSetup.firstLine = 1;
+ const negativeResult = testSetup.SetLines(["template<typename T> bool \n", "foo(T a);"]).GetResult();
+ assert.equal("/**\n * @brief \n * \n */", negativeResult);
});
});
diff --git a/src/test/CppTests/TestSetup.ts b/src/test/CppTests/TestSetup.ts
index ee7256d..2e6c7f1 100644
--- a/src/test/CppTests/TestSetup.ts
+++ b/src/test/CppTests/TestSetup.ts
@@ -13,11 +13,12 @@ import MockSelection from "../tools/MockSelection";
export default class TestSetup {
public cfg: Config;
-
+ public firstLine: number;
private editor: MockEditor;
constructor(method: string) {
this.cfg = new Config();
+ this.firstLine = 0;
this.SetLine(method);
}
@@ -38,7 +39,7 @@ export default class TestSetup {
.map((l) => new MockLine(l));
}
- const selection: MockSelection = new MockSelection(new MockPosition(0, 0));
+ const selection: MockSelection = new MockSelection(new MockPosition(this.firstLine, 0));
const doc: MockDocument = new MockDocument(mockLines);
this.editor = new MockEditor(selection, doc);
@@ -51,7 +52,8 @@ export default class TestSetup {
parser = new CppParser(this.cfg);
const gen: IDocGen = parser.Parse(this.editor);
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
+ // tslint:disable-next-line:max-line-length
+ gen.GenerateDoc(new vscode.Range(new vscode.Position(this.firstLine, 0), new vscode.Position(this.firstLine, 0)));
return this.editor.editBuilder.text;
}
diff --git a/src/test/tools/MockDocument.ts b/src/test/tools/MockDocument.ts
index 781dbfe..1dca76e 100644
--- a/src/test/tools/MockDocument.ts
+++ b/src/test/tools/MockDocument.ts
@@ -14,6 +14,7 @@ export default class MockDocument implements vscode.TextDocument {
private lines: vscode.TextLine[];
public constructor(lines: vscode.TextLine[]) {
this.lines = lines;
+ this.fileName = "MockDocument.h";
}
public save(): Thenable<boolean> {
throw new Error("Method not implemented.");