diff options
| author | Christoph Schlosser <christoph@linux.com> | 2019-06-22 13:42:30 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2019-06-22 13:42:30 +0200 |
| commit | 68e28690ae7c199e4c1f75d33f863878d8592ef5 (patch) | |
| tree | 8cb8fe7bbdd494760a33e3fa557eb9024b42be87 | |
| parent | 969fd3d3f5572f31c955c5b719a8e889cecda76b (diff) | |
| download | doxdocgen-68e28690ae7c199e4c1f75d33f863878d8592ef5.tar.gz | |
Current WIP
| -rw-r--r-- | package.json | 5 | ||||
| -rw-r--r-- | src/Config.ts | 2 | ||||
| -rw-r--r-- | 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<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); + values.Generic.indentWidth = Generic.getConfiguration().get<number>("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; } |