From 68e28690ae7c199e4c1f75d33f863878d8592ef5 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 13:42:30 +0200 Subject: Current WIP --- package.json | 5 +++++ src/Config.ts | 2 ++ src/Lang/Cpp/CppDocGen.ts | 28 ++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 8302a6e..2cfa4c1 100644 --- a/package.json +++ b/package.json @@ -176,6 +176,11 @@ "type": "boolean", "default": true }, + "doxdocgen.generic.indentWidth": { + "description": "At how many spaces the documentation should be inserted. Only Valid for param and tparam.", + "type": "number", + "default": 0 + }, "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"], diff --git a/src/Config.ts b/src/Config.ts index b33aff2..8c3e723 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -57,6 +57,7 @@ class Generic { public generateSmartText: boolean = true; public splitCasingSmartText: boolean = true; public order: string[] = ["brief", "empty", "tparam", "param", "return"]; + public indentWidth: number = 0; } export class Config { @@ -95,6 +96,7 @@ export class Config { values.Generic.generateSmartText = Generic.getConfiguration().get("generateSmartText", values.Generic.generateSmartText); values.Generic.splitCasingSmartText = Generic.getConfiguration().get("splitCasingSmartText", values.Generic.splitCasingSmartText); values.Generic.order = Generic.getConfiguration().get("order", values.Generic.order); + values.Generic.indentWidth = Generic.getConfiguration().get("indentWidth", values.Generic.indentWidth); return values; } diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 75b67af..481a349 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -101,8 +101,14 @@ export class CppDocGen implements IDocGen { return this.activeEditor.document.lineAt(this.activeEditor.selection.start.line).text.match("^\\s*")[0]; } - protected getTemplatedString(replace: string, template: string, param: string): string { - return template.replace(replace, param); + protected getTemplatedString(replace: string, template: string, param: string, indent: boolean = false): string { + let indentWidth: string = ""; + if (indent === true) { + const numSpaces = Math.max(this.cfg.Generic.indentWidth - param.length, 0); + indentWidth = " ".repeat(numSpaces); + } + const indentedTemplate = template.replace(replace, replace + indentWidth); + return indentedTemplate.replace(replace, param); } protected getMultiTemplatedString(replace: string[], template: string, param: string[]): string { @@ -177,14 +183,18 @@ export class CppDocGen implements IDocGen { this.getSmartText())); } - protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) { + protected generateFromTemplate(lines: string[], + replace: string, + template: string, + templateWith: string[], + indent: boolean = false) { let line: string = ""; templateWith.forEach((element: string) => { // Ignore null values if (element !== null) { line = this.cfg.C.commentPrefix; - line += this.getTemplatedString(replace, template, element); + line += this.getTemplatedString(replace, template, element, indent); lines.push(line); } }); @@ -385,6 +395,7 @@ export class CppDocGen implements IDocGen { this.cfg.paramTemplateReplace, this.cfg.Cpp.tparamTemplate, this.templateParams, + true, ); } break; @@ -392,8 +403,13 @@ export class CppDocGen implements IDocGen { 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); + this.generateFromTemplate( + lines, + this.cfg.paramTemplateReplace, + this.cfg.Generic.paramTemplate, + paramNames, + true, + ); } break; } -- cgit v1.2.3 From 24f919cccad600fcf32d86ec90edfeec21a372ab Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 18:02:51 +0200 Subject: Add maintained badge --- README.md | 1 + package.json | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index d1f1f16..193fd60 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ This VS Code Extensions provides Doxygen Documentation generation on the fly by [![Build status](https://ci.appveyor.com/api/projects/status/4h84071p9tv0y9r6?svg=true)](https://ci.appveyor.com/project/christophschlosser/doxdocgen) [![codecov](https://codecov.io/gh/christophschlosser/doxdocgen/branch/master/graph/badge.svg)](https://codecov.io/gh/christophschlosser/doxdocgen) [![Gitter chat](https://badges.gitter.im/doxdocgen.png)](https://gitter.im/doxdocgen) +[![Average time to resolve an issue](https://isitmaintained.com/badge/resolution/christophschlosser/doxdocgen.svg)](https://isitmaintained.com/project/christophschlosser/doxdocgen "Average time to resolve an issue") ## Table of Contents diff --git a/package.json b/package.json index 2cfa4c1..55f24f3 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,11 @@ "url": "https://codecov.io/gh/christophschlosser/doxdocgen/branch/master/graph/badge.svg", "href": "https://codecov.io/gh/christophschlosser/doxdocgen", "description": "Code coverage" + }, + { + "url": "https://isitmaintained.com/badge/resolution/christophschlosser/doxdocgen.svg", + "href": "https://isitmaintained.com/project/christophschlosser/doxdocgen", + "description": "Response time for issues" } ], "activationEvents": [ -- cgit v1.2.3 From 61bc1fafb3778e12afafa41757c14f4360a9c663 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 18:39:58 +0200 Subject: Enable indent also for return --- src/Lang/Cpp/CppDocGen.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 51a975f..eb2f01a 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -122,7 +122,8 @@ export class CppDocGen implements IDocGen { protected getTemplatedString(replace: string, template: string, param: string, indent: boolean = false): string { let indentWidth: string = ""; if (indent === true) { - const numSpaces = Math.max(this.cfg.Generic.indentWidth - param.length, 0); + const replacedTemplate = template.replace(replace, param); + const numSpaces = Math.max(this.cfg.Generic.indentWidth - replacedTemplate.length, 0); indentWidth = " ".repeat(numSpaces); } const indentedTemplate = template.replace(replace, replace + indentWidth); @@ -435,7 +436,8 @@ export class CppDocGen implements IDocGen { 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.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.Generic.returnTemplate, returnParams, + true); } break; } -- cgit v1.2.3 From 1ca956daf7bcba223f14400f21b9695616b0f1d6 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Fri, 28 Jun 2019 22:27:09 +0200 Subject: Indents anywhere {indent:number} can be used to align parameters, text blocks and all at cetain limits. --- src/Lang/Cpp/CppDocGen.ts | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index eb2f01a..1c00546 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -119,15 +119,34 @@ export class CppDocGen implements IDocGen { return this.activeEditor.document.lineAt(this.activeEditor.selection.start.line).text.match("^\\s*")[0]; } - protected getTemplatedString(replace: string, template: string, param: string, indent: boolean = false): string { - let indentWidth: string = ""; - if (indent === true) { - const replacedTemplate = template.replace(replace, param); - const numSpaces = Math.max(this.cfg.Generic.indentWidth - replacedTemplate.length, 0); - indentWidth = " ".repeat(numSpaces); + protected getIndentedTemplate(replace: string): string { + if (replace === undefined || replace === null || replace === "") { + return ""; } - const indentedTemplate = template.replace(replace, replace + indentWidth); - return indentedTemplate.replace(replace, param); + const snippets = replace.split(/({indent:\d+})/); + + let indentedString: string = ""; + let indentWidth: number = 0; + + // tslint:disable-next-line:prefer-for-of + snippets.forEach((element) => { + if (element.match(/{indent:\d+}/)) { + const indents = parseInt(element.match(/{indent:(\d+)}/)[1], 10); + indentWidth = indents; + const numSpaces = Math.max(indentWidth - indentedString.length, 0); + indentedString += " ".repeat(numSpaces); + } else { + // just some text + indentedString += element; + } + }); + + return indentedString; + } + + protected getTemplatedString(replace: string, template: string, param: string): string { + const replacedTemplate = template.replace(replace, param); + return this.getIndentedTemplate(replacedTemplate); } protected getMultiTemplatedString(replace: string[], template: string, param: string[]): string { @@ -205,15 +224,14 @@ export class CppDocGen implements IDocGen { protected generateFromTemplate(lines: string[], replace: string, template: string, - templateWith: string[], - indent: boolean = false) { + templateWith: string[]) { let line: string = ""; templateWith.forEach((element: string) => { // Ignore null values if (element !== null) { line = this.cfg.C.commentPrefix; - line += this.getTemplatedString(replace, template, element, indent); + line += this.getTemplatedString(replace, template, element); lines.push(line); } }); @@ -414,7 +432,6 @@ export class CppDocGen implements IDocGen { this.cfg.paramTemplateReplace, this.cfg.Cpp.tparamTemplate, this.templateParams, - true, ); } break; @@ -427,7 +444,6 @@ export class CppDocGen implements IDocGen { this.cfg.paramTemplateReplace, this.cfg.Generic.paramTemplate, paramNames, - true, ); } break; @@ -436,8 +452,7 @@ export class CppDocGen implements IDocGen { 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, - true); + this.generateFromTemplate(lines, this.cfg.typeTemplateReplace, this.cfg.Generic.returnTemplate, returnParams); } break; } -- cgit v1.2.3 From 1d863f634d197c786904e9d4ea87a556f9859af9 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Fri, 28 Jun 2019 22:41:27 +0200 Subject: Remove previous implementation --- package.json | 5 ----- src/Config.ts | 2 -- 2 files changed, 7 deletions(-) diff --git a/package.json b/package.json index 0e19d96..59f776b 100644 --- a/package.json +++ b/package.json @@ -181,11 +181,6 @@ "type": "boolean", "default": true }, - "doxdocgen.generic.indentWidth": { - "description": "At how many spaces the documentation should be inserted. Only Valid for param and tparam.", - "type": "number", - "default": 0 - }, "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"], diff --git a/src/Config.ts b/src/Config.ts index 8c3e723..b33aff2 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -57,7 +57,6 @@ class Generic { public generateSmartText: boolean = true; public splitCasingSmartText: boolean = true; public order: string[] = ["brief", "empty", "tparam", "param", "return"]; - public indentWidth: number = 0; } export class Config { @@ -96,7 +95,6 @@ export class Config { values.Generic.generateSmartText = Generic.getConfiguration().get("generateSmartText", values.Generic.generateSmartText); values.Generic.splitCasingSmartText = Generic.getConfiguration().get("splitCasingSmartText", values.Generic.splitCasingSmartText); values.Generic.order = Generic.getConfiguration().get("order", values.Generic.order); - values.Generic.indentWidth = Generic.getConfiguration().get("indentWidth", values.Generic.indentWidth); return values; } -- cgit v1.2.3 From b4193c57675c394af91aeb745e6e8175ca827a01 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Fri, 28 Jun 2019 23:13:09 +0200 Subject: Fix brief and add tests --- src/Lang/Cpp/CppDocGen.ts | 4 ++-- src/test/CppTests/Config.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 1c00546..5d2483f 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -216,8 +216,8 @@ export class CppDocGen implements IDocGen { } protected generateBrief(lines: string[]) { - lines.push(this.getTemplatedString(this.cfg.textTemplateReplace, - this.cfg.C.commentPrefix + this.cfg.Generic.briefTemplate, + lines.push(this.cfg.C.commentPrefix + this.getTemplatedString(this.cfg.textTemplateReplace, + this.cfg.Generic.briefTemplate, this.getSmartText())); } diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts index 1ef2a4d..8d0d447 100644 --- a/src/test/CppTests/Config.test.ts +++ b/src/test/CppTests/Config.test.ts @@ -158,4 +158,27 @@ suite("C++ - Configuration Tests", () => { const result = testSetup.SetLines(["*/", "int foo();"]).GetResult(); assert.equal("/**\n * @brief \n * \n * @return int \n */", result); }); + + test("Single alignment", () => { + testSetup.cfg.Generic.paramTemplate = "@param{indent:10}{param}"; + testSetup.cfg.Cpp.tparamTemplate = "@tparam{indent:10}{param}"; + testSetup.cfg.Generic.returnTemplate = "@return{indent:10}{type}"; + testSetup.cfg.Generic.briefTemplate = "@brief{indent:10}Brief"; + + const result = testSetup.SetLines(["template", "int foo(std::string bar, T foobar);"]).GetResult(); + // tslint:disable-next-line:max-line-length + assert.equal("/**\n * @brief Brief\n * \n * @tparam T\n * @param bar\n * @param foobar\n * @return int\n */", result); + }); + + test("Multi alignment", () => { + testSetup.cfg.Generic.paramTemplate = "@param{indent:10}{param}{indent:30}Parameters everywhere"; + testSetup.cfg.Cpp.tparamTemplate = "@tparam{indent:10}{param}{indent:30}I'm a template"; + testSetup.cfg.Generic.returnTemplate = "@return{indent:10}{type}{indent:30}Returns stuff"; + testSetup.cfg.Generic.briefTemplate = "@brief{indent:30}Short desc"; + + const result = testSetup.SetLines(["template", "int foo(std::string bar, T foobar);"]).GetResult(); + // tslint:disable-next-line:max-line-length + assert.equal("/**\n * @brief Short desc\n * \n * @tparam T I'm a template\n * @param bar Parameters everywhere\n * @param foobar Parameters everywhere\n * @return int Returns stuff\n */", result); + }); + }); -- cgit v1.2.3 From c79177e7990359be7cd28146b10f198bd4102b56 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Fri, 28 Jun 2019 23:25:22 +0200 Subject: Negative test --- src/test/CppTests/Config.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts index 8d0d447..b218de9 100644 --- a/src/test/CppTests/Config.test.ts +++ b/src/test/CppTests/Config.test.ts @@ -181,4 +181,12 @@ suite("C++ - Configuration Tests", () => { assert.equal("/**\n * @brief Short desc\n * \n * @tparam T I'm a template\n * @param bar Parameters everywhere\n * @param foobar Parameters everywhere\n * @return int Returns stuff\n */", result); }); + test("Negative alignment tests", () => { + testSetup.cfg.Generic.returnTemplate = ""; + + const result = testSetup.SetLines(["template", "int foo(std::string bar, T foobar);"]).GetResult(); + // tslint:disable-next-line:max-line-length + assert.equal("/**\n * @brief Short desc\n * \n * @tparam T I'm a template\n * @param bar Parameters everywhere\n * @param foobar Parameters everywhere\n */", result); + }); + }); -- cgit v1.2.3 From 903fdc1d30c288a9794ebcf9052112712b10080c Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Fri, 28 Jun 2019 23:49:40 +0200 Subject: Document the alignment feature --- CHANGELOG.md | 41 +++++++++++++++++++++++++++++++++++++++++ README.md | 6 ++++++ images/alignment.gif | Bin 0 -> 129756 bytes 3 files changed, 47 insertions(+) create mode 100644 images/alignment.gif diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c9ed6d..67605c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,46 @@ # Change Log +## [0.5.0] + +### Feature + +- Feature suggest: Indent option (#107) + +#### Alignment + +This version introduces the possibility to align text elements in config strings at a specified width. + +Example: + +```json +"doxdocgen.generic.paramTemplate": "@param{indent:10}{param}{indent:30}My Param doc" +``` + +will turn into + +```cpp +/** + * @param foo My Param doc + * @param barIsAlsoAnOption My Param doc + */ +void bar(int foo, int barIsAlsoAnOption); +``` + +You can use the `{indent:}` in any templated config option available. Numbers have to be bigger than 0 to have any effect. + +Alignment will be done from the start of the config string, like this: + +```json +"doxdocgen.generic.paramTemplate": "@param {param}{indent:14}test" +``` + +```cpp +/** + * @param test + */ + |<---------->| // 14 +``` + ## [0.4.3] ### Fix diff --git a/README.md b/README.md index 193fd60..32dd759 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ This VS Code Extensions provides Doxygen Documentation generation on the fly by ## Features +### Alignment + +![Alignment](images/alignment.gif) + +For how this works, see the [CHANGELOG.md](https://github.com/christophschlosser/doxdocgen/blob/master/CHANGELOG.md#alignment) + ### Attributes ![Attribute](images/attributes.gif) diff --git a/images/alignment.gif b/images/alignment.gif new file mode 100644 index 0000000..dc9e9b8 Binary files /dev/null and b/images/alignment.gif differ -- cgit v1.2.3