diff options
| author | Christoph Schlosser <christoph@linux.com> | 2018-03-02 22:21:22 +0100 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2018-03-02 23:27:10 +0100 |
| commit | 16452c8e0c644fa979270e99906eb9c34a13ca5f (patch) | |
| tree | 25173bf8f8b79167193ce36094bf80399b1ea724 | |
| parent | b837545df65a31ba5dac154644c359c2a55d1531 (diff) | |
| download | doxdocgen-16452c8e0c644fa979270e99906eb9c34a13ca5f.tar.gz | |
Make order of comment tags customizable
Fix #55
| -rw-r--r-- | README.md | 19 | ||||
| -rw-r--r-- | package.json | 24 | ||||
| -rw-r--r-- | src/Config.ts | 10 | ||||
| -rw-r--r-- | src/Lang/Cpp/CppDocGen.ts | 74 | ||||
| -rw-r--r-- | src/test/CppTests/Config.test.ts | 22 |
5 files changed, 83 insertions, 66 deletions
@@ -124,15 +124,13 @@ Each of them can be configured with its own custom text and you can decide if th // Smart text snippet for destructors. "doxdocgen.cpp.dtorText": "Destroy the {name} object", -// Whether to insert a newline after the template params. -"doxdocgen.cpp.newLineAfterTParams": false, - // The template of the template parameter DoxyGen line(s) that are generated. If empty it won't get generated at all. "doxdocgen.cpp.tparamTemplate": "@tparam {param} ", -// The order to use for the date. Valid values are shown in default setting. +// The order to use for the file comment. Values can be used multiple times. Valid values are shown in default setting. "doxdocgen.file.fileOrder": [ "brief", + "empty", "file", "author", "date" @@ -165,11 +163,14 @@ Each of them can be configured with its own custom text and you can decide if th // 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. "doxdocgen.generic.linesToGet": 20, -// Whether to insert a newline after a brief. -"doxdocgen.generic.newLineAfterBrief": true, - -// Whether to insert a newline after the params. -"doxdocgen.generic.newLineAfterParams": false, +// The order to use for the comment generation. Values can be used multiple times. Valid values are shown in default setting. +"doxdocgen.generic.order": [ + "brief", + "empty", + "tparam", + "param", + "return" +], // The template of the param DoxyGen line(s) that are generated. If empty it won't get generated at all. "doxdocgen.generic.paramTemplate": "@param {param} ", diff --git a/package.json b/package.json index 0ba91da..1b89a55 100644 --- a/package.json +++ b/package.json @@ -71,11 +71,6 @@ "type": "string", "default": "Create a {name} object" }, - "doxdocgen.cpp.newLineAfterTParams": { - "description": "Whether to insert a newline after the template params.", - "type": "boolean", - "default": false - }, "doxdocgen.cpp.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", @@ -97,19 +92,9 @@ "default": "@file {name}" }, "doxdocgen.file.fileOrder": { - "description": "The order to use for the date. Valid values are shown in default setting.", + "description": "The order to use for the file comment. Values can be used multiple times. Valid values are shown in default setting.", "type": ["array", "string"], - "default": ["brief", "file", "author", "date"] - }, - "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 + "default": ["brief", "empty", "file", "author", "date"] }, "doxdocgen.generic.includeTypeAtReturn": { "description": "Whether include type information at return.", @@ -165,6 +150,11 @@ "description": "Decide if the values put into {name} should be split according to their casing.", "type": "boolean", "default": true + }, + "doxdocgen.generic.order": { + "description": "The order to use for the comment generation. Values can be used multiple times. Valid values are shown in default setting.", + "type": ["array", "string"], + "default": ["brief", "empty", "tparam", "param", "return"] } } } diff --git a/src/Config.ts b/src/Config.ts index aed2105..0fcd5a2 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -21,7 +21,6 @@ class Cpp { return workspace.getConfiguration("doxdocgen.cpp"); } - public newLineAfterTParams: boolean = false; public tparamTemplate: string = "@tparam {param} "; public ctorText: string = "Construct a new {name} object"; public dtorText: string = "Destroy the {name} object"; @@ -33,7 +32,7 @@ class File { } public fileTemplate: string = "@file {name}"; - public fileOrder: string[] = ["brief", "file", "author", "date"]; + public fileOrder: string[] = ["brief", "empty", "file", "author", "date"]; } class Generic { @@ -41,8 +40,6 @@ class Generic { return workspace.getConfiguration("doxdocgen.generic"); } - public newLineAfterBrief: boolean = true; - public newLineAfterParams: boolean = false; public includeTypeAtReturn: boolean = true; public boolReturnsTrueFalse: boolean = true; public briefTemplate: string = "@brief "; @@ -54,6 +51,7 @@ class Generic { public dateFormat: string = "YYYY-MM-DD"; public generateSmartText: boolean = true; public splitCasingSmartText: boolean = true; + public order: string[] = ["brief", "empty", "tparam", "param", "return"]; } export class Config { @@ -68,7 +66,6 @@ export class Config { values.C.setterText = C.getConfiguration().get<string>("setterText", values.C.setterText); values.C.factoryMethodText = C.getConfiguration().get<string>("factoryMethodText", values.C.factoryMethodText); - values.Cpp.newLineAfterTParams = Cpp.getConfiguration().get<boolean>("newLineAfterTParams", values.Cpp.newLineAfterTParams); values.Cpp.tparamTemplate = Cpp.getConfiguration().get<string>("tparamTemplate", values.Cpp.tparamTemplate); values.Cpp.ctorText = Cpp.getConfiguration().get<string>("ctorText", values.Cpp.ctorText); values.Cpp.dtorText = Cpp.getConfiguration().get<string>("dtorText", values.Cpp.dtorText); @@ -76,8 +73,6 @@ export class Config { values.File.fileTemplate = File.getConfiguration().get<string>("fileTemplate", values.File.fileTemplate); values.File.fileOrder = File.getConfiguration().get<string[]>("fileOrder", values.File.fileOrder); - values.Generic.newLineAfterBrief = Generic.getConfiguration().get<boolean>("newLineAfterBrief", values.Generic.newLineAfterBrief); - values.Generic.newLineAfterParams = Generic.getConfiguration().get<boolean>("newLineAfterParams", values.Generic.newLineAfterParams); values.Generic.includeTypeAtReturn = Generic.getConfiguration().get<boolean>("includeTypeAtReturn", values.Generic.includeTypeAtReturn); values.Generic.boolReturnsTrueFalse = Generic.getConfiguration().get<boolean>("boolReturnsTrueFalse", values.Generic.boolReturnsTrueFalse); values.Generic.briefTemplate = Generic.getConfiguration().get<string>("briefTemplate", values.Generic.briefTemplate); @@ -89,6 +84,7 @@ export class Config { values.Generic.dateFormat = Generic.getConfiguration().get<string>("dateFormat", values.Generic.dateFormat); values.Generic.generateSmartText = Generic.getConfiguration().get<boolean>("generateSmartText", values.Generic.generateSmartText); values.Generic.splitCasingSmartText = Generic.getConfiguration().get<boolean>("splitCasingSmartText", values.Generic.splitCasingSmartText); + values.Generic.order = Generic.getConfiguration().get<string[]>("order", values.Generic.order); return values; } diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 1a03430..56ce922 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -247,9 +247,6 @@ export class CppDocGen implements IDocGen { protected insertBrief(lines: string[]) { if (this.cfg.Generic.briefTemplate.trim().length !== 0) { this.generateBrief(lines); - if (this.cfg.Generic.newLineAfterBrief === true) { - lines.push(this.cfg.C.commentPrefix); - } } } @@ -270,6 +267,10 @@ export class CppDocGen implements IDocGen { this.insertBrief(lines); break; } + case "empty": { + lines.push(this.cfg.C.commentPrefix); + break; + } case "file": { this.generateFilenameFromTemplate(lines); break; @@ -298,33 +299,48 @@ export class CppDocGen implements IDocGen { this.insertFirstLine(lines); - this.insertBrief(lines); - - if (this.cfg.Cpp.tparamTemplate.trim().length !== 0 && this.templateParams.length > 0) { - this.generateFromTemplate( - lines, - this.cfg.paramTemplateReplace, - this.cfg.Cpp.tparamTemplate, - this.templateParams, - ); - if (this.cfg.Cpp.newLineAfterTParams === true) { - lines.push(this.cfg.C.commentPrefix); - } - } - - if (this.cfg.Generic.paramTemplate.trim().length !== 0 && this.params.length > 0) { - const paramNames: string[] = this.params.map((p) => p.name); - this.generateFromTemplate(lines, this.cfg.paramTemplateReplace, this.cfg.Generic.paramTemplate, paramNames); - if (this.cfg.Generic.newLineAfterParams === true) { - lines.push(this.cfg.C.commentPrefix); + this.cfg.Generic.order.forEach((element) => { + switch (element) { + case "brief": { + this.insertBrief(lines); + break; + } + case "empty": { + lines.push(this.cfg.C.commentPrefix); + break; + } + case "tparam": { + if (this.cfg.Cpp.tparamTemplate.trim().length !== 0 && this.templateParams.length > 0) { + this.generateFromTemplate( + lines, + this.cfg.paramTemplateReplace, + this.cfg.Cpp.tparamTemplate, + this.templateParams, + ); + } + break; + } + case "param": { + if (this.cfg.Generic.paramTemplate.trim().length !== 0 && this.params.length > 0) { + const paramNames: string[] = this.params.map((p) => p.name); + // tslint:disable-next-line:max-line-length + this.generateFromTemplate(lines, this.cfg.paramTemplateReplace, this.cfg.Generic.paramTemplate, paramNames); + } + break; + } + case "return": { + if (this.cfg.Generic.returnTemplate.trim().length !== 0 && this.func.type !== null) { + const returnParams = this.generateReturnParams(); + // tslint:disable-next-line:max-line-length + this.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.Generic.returnTemplate, returnParams); + } + break; + } + default: { + break; + } } - } - - if (this.cfg.Generic.returnTemplate.trim().length !== 0 && this.func.type !== null) { - const returnParams = this.generateReturnParams(); - // tslint:disable-next-line:max-line-length - this.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.Generic.returnTemplate, returnParams); - } + }); this.insertLastLine(lines); diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts index ee6a90f..69837ce 100644 --- a/src/test/CppTests/Config.test.ts +++ b/src/test/CppTests/Config.test.ts @@ -25,6 +25,21 @@ suite("C++ - Configuration Tests", () => { + "@return true \n * @return false \n */", result); }); + test("Comment order", () => { + testSetup.cfg = new Config(); + testSetup.cfg.Generic.order = ["brief", "param", "tparam", "return"]; + const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult(); + assert.equal("/**\n * @brief \n * @param a \n * @tparam T \n * " + + "@return true \n * @return false \n */", result); + }); + + test("Non existing order param", () => { + testSetup.cfg = new Config(); + testSetup.cfg.Generic.order = ["breif"]; + const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult(); + assert.equal("/**\n */", result); + }); + test("Modified template", () => { testSetup.cfg = new Config(); @@ -61,11 +76,10 @@ suite("C++ - Configuration Tests", () => { test("Newlines after params and tparams but not after brief", () => { testSetup.cfg = new Config(); - testSetup.cfg.Generic.newLineAfterBrief = false; - testSetup.cfg.Generic.newLineAfterParams = true; - testSetup.cfg.Cpp.newLineAfterTParams = true; + testSetup.cfg.Generic.order = ["brief", "tparam", "empty", "param", "empty", "return"]; const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult(); + testSetup.cfg.Generic.order = ["brief", "empty", "tparam", "param", "return"]; // reset to default assert.equal("/**\n * @brief \n * @tparam T \n * \n * @param a \n * \n" + " * @return true \n * @return false \n */", result); }); @@ -99,7 +113,7 @@ suite("C++ - Configuration Tests", () => { testSetup.firstLine = 0; testSetup.cfg.File.fileOrder = ["brief", "author", "date", "file"]; const result = testSetup.SetLine("").GetResult(); - assert.equal("/**\n * @brief \n * \n * @author your name\n" + + assert.equal("/**\n * @brief \n * @author your name\n" + " * @date " + moment().format("YYYY-MM-DD") + "\n * @file MockDocument.h\n */", result); }); |