summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christophschlosser@users.noreply.github.com>2019-06-28 23:56:15 +0200
committerGitHub <noreply@github.com>2019-06-28 23:56:15 +0200
commit75e169ef3aebcf7a75edba4fa28bee370782b00b (patch)
tree589fad4429487bce7efbbc8daa756a909ebdfcd6
parent2d7a744527e469397a6dce6f27d60fac4382ee53 (diff)
parent903fdc1d30c288a9794ebcf9052112712b10080c (diff)
downloaddoxdocgen-75e169ef3aebcf7a75edba4fa28bee370782b00b.tar.gz
Merge pull request #116 from christophschlosser/indent-option
Indent option
-rw-r--r--CHANGELOG.md41
-rw-r--r--README.md7
-rw-r--r--images/alignment.gifbin0 -> 129756 bytes
-rw-r--r--package.json5
-rw-r--r--src/Lang/Cpp/CppDocGen.ts45
-rw-r--r--src/test/CppTests/Config.test.ts31
6 files changed, 123 insertions, 6 deletions
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:<number>}` 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 d1f1f16..32dd759 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
@@ -28,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
--- /dev/null
+++ b/images/alignment.gif
Binary files differ
diff --git a/package.json b/package.json
index 324b067..59f776b 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": [
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index bc5a355..5d2483f 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -119,8 +119,34 @@ export class CppDocGen implements IDocGen {
return this.activeEditor.document.lineAt(this.activeEditor.selection.start.line).text.match("^\\s*")[0];
}
+ protected getIndentedTemplate(replace: string): string {
+ if (replace === undefined || replace === null || replace === "") {
+ return "";
+ }
+ 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 {
- return template.replace(replace, param);
+ const replacedTemplate = template.replace(replace, param);
+ return this.getIndentedTemplate(replacedTemplate);
}
protected getMultiTemplatedString(replace: string[], template: string, param: string[]): string {
@@ -190,12 +216,15 @@ 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()));
}
- protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) {
+ protected generateFromTemplate(lines: string[],
+ replace: string,
+ template: string,
+ templateWith: string[]) {
let line: string = "";
templateWith.forEach((element: string) => {
@@ -410,8 +439,12 @@ 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,
+ );
}
break;
}
diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts
index 1ef2a4d..b218de9 100644
--- a/src/test/CppTests/Config.test.ts
+++ b/src/test/CppTests/Config.test.ts
@@ -158,4 +158,35 @@ 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<typename T>", "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<typename T>", "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);
+ });
+
+ test("Negative alignment tests", () => {
+ testSetup.cfg.Generic.returnTemplate = "";
+
+ const result = testSetup.SetLines(["template<typename T>", "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);
+ });
+
});