From 68e28690ae7c199e4c1f75d33f863878d8592ef5 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 13:42:30 +0200 Subject: Current WIP --- src/Lang/Cpp/CppDocGen.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/Lang/Cpp/CppDocGen.ts') 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 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(-) (limited to 'src/Lang/Cpp/CppDocGen.ts') 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(-) (limited to 'src/Lang/Cpp/CppDocGen.ts') 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 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Lang/Cpp/CppDocGen.ts') 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())); } -- cgit v1.2.3