From 0ebfa5bd12e529d8febe73c85d3bf48c4d4997e8 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sat, 14 Oct 2017 22:29:02 +0200 Subject: -- Added extensive templating the be able to generated different types of doxygen comment. --- src/DocGen/CGen.ts | 172 +++++++++++++++++++++++++-------------------------- src/DocGen/DocGen.ts | 19 ++---- 2 files changed, 91 insertions(+), 100 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 426bb26..97ba12e 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -1,66 +1,76 @@ -import { Position, Range, Selection, TextEditor, TextLine, WorkspaceEdit } from "vscode"; -import { DoxygenCommands, IDocGen } from "./DocGen"; +import { Position, Range, Selection, TextEditor, TextLine, WorkspaceEdit, workspace } from "vscode"; +import { IDocGen } from "./DocGen"; +import { Config, ConfigType } from "../Config"; export default class CGen implements IDocGen { - protected lineStart: string; - protected endComment: string; - protected commandIndicator: string; - protected spaceAfterCommand: string; + protected firstLine: string; + protected commentPrefix: string; + protected lastLine: string; + protected newLineAfterBrief: boolean; + protected newLineAfterParams: boolean; + protected newLineAfterTParams: boolean; + protected briefTemplate: string; + protected paramTemplate: string; + protected tparamTemplate: string; + protected returnTemplate: string; + + protected templateReplaceString: string; + protected activeEditor: TextEditor; protected position: Position; - protected comment: string; protected retVals: string[]; protected params: string[]; + protected tparams: string[]; /** * @param {TextEditor} actEdit Active editor window * @param {Position} cursorPosition Where the cursor of the user currently is * @param {string[]} param The parameter names of the method extracted by the parser + * @param {string[]} tparam The template parameter names of the method extracted by the parser. * @param {string[]} returnVals The return values extracted by the parser */ - public constructor(actEdit: TextEditor, cursorPosition: Position, param: string[], returnVals: string[]) { + public constructor(actEdit: TextEditor, cursorPosition: Position, param: string[], tparam: string[], returnVals: string[]) { this.activeEditor = actEdit; this.position = cursorPosition; - this.comment = "\n"; // Add the new line after the comment indicator + this.templateReplaceString = "{param}"; this.params = param; + this.tparams = tparam; this.retVals = returnVals; } /** * @inheritdoc */ - public GenerateDoc() { + public GenerateDoc(rangeToReplace: Range) { this.readConfig(); - this.generateComment(); - - const oldPos: Position = this.position; + const comment: string = this.generateComment(); - const active: Position = this.activeEditor.selection.active; - const anchor: Position = new Position(active.line + 1, active.character); // Start at the next line - const replaceSelection = new Selection(anchor, active); this.activeEditor.edit((editBuilder) => { - editBuilder.replace(replaceSelection, this.comment); // Insert the comment + editBuilder.replace(rangeToReplace, comment); // Insert the comment }); // Set cursor after brief command - this.setCursor(oldPos.line + 3, oldPos.character); - const newSelectActive = new Position(oldPos.line + 3, oldPos.character + DoxygenCommands.detailed.length); - const newSelectPos = new Position(oldPos.line + 3, oldPos.character); - this.activeEditor.selection = new Selection(newSelectPos, newSelectActive); + this.setCursorToBrief(rangeToReplace.start.line, rangeToReplace.start.character); } /*************************************************************************** Implementation ***************************************************************************/ - protected readConfig() { - this.lineStart = " * "; // TODO: make this customizable - this.endComment = "*/"; // TODO: make this customizable - this.commandIndicator = "@"; // TODO: make this customizable - this.spaceAfterCommand = " "; // TODO: make this customizable + protected readConfig() { + this.firstLine = workspace.getConfiguration(ConfigType.generic).get(Config.firstLine, ""); + this.commentPrefix = workspace.getConfiguration(ConfigType.generic).get(Config.commentPrefix, ""); + this.lastLine = workspace.getConfiguration(ConfigType.generic).get(Config.lastLine, ""); + this.newLineAfterBrief = workspace.getConfiguration(ConfigType.generic).get(Config.newLineAfterBrief, true); + this.newLineAfterParams = workspace.getConfiguration(ConfigType.generic).get(Config.newLineAfterParams, false); + this.newLineAfterTParams = workspace.getConfiguration(ConfigType.generic).get(Config.newLineAfterTParams, false); + this.briefTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.briefTemplate, ""); + this.paramTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.paramTemplate, ""); + this.tparamTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.tparamTemplate, ""); + this.returnTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.returnTemplate, ""); } - protected indentLine(commentLine: string): string { + protected getIndentation(): string { const line: TextLine = this.activeEditor.document.lineAt(this.activeEditor.selection.start.line); const lineTxt: string = line.text; let stringToIndent: string = ""; @@ -72,85 +82,75 @@ export default class CGen implements IDocGen { stringToIndent = stringToIndent + " "; } } - const textToInsert = stringToIndent + commentLine; - return textToInsert; + return stringToIndent; } - protected generateBrief() { - let line: string = ""; - line += this.lineStart; - line += this.commandIndicator; - line += DoxygenCommands.brief; - line += this.spaceAfterCommand; - this.comment += this.indentLine(line); + protected getTemplatedString(template: string, param: string): string { + return template.replace(this.templateReplaceString, param); } - protected generateDetailed() { - let line: string = ""; - line += this.lineStart; - line += "\n"; - this.comment += this.indentLine(line); - line = this.lineStart; - line += DoxygenCommands.detailed + "\n"; - this.comment += this.indentLine(line); - line = this.lineStart; - this.comment += this.indentLine(line); + protected generateBrief(lines: string[]) { + lines.push(this.commentPrefix + this.briefTemplate); } - protected generateParams() { + protected generateFromTemplate(lines: string[], template: string, templateWith: string[]) { let line: string = ""; - this.params.forEach((element: string) => { - line = this.lineStart; - line += this.commandIndicator; - line += DoxygenCommands.param + " "; // TODO: Make this customizable - line += element + "\n"; - this.comment += this.indentLine(line); + templateWith.forEach((element: string) => { + line = this.commentPrefix; + line += this.getTemplatedString(template, element); + lines.push(line); }); } - protected generateReturn() { - if (this.retVals.length === 0) { - return; + protected generateComment(): string { + let lines: string[] = []; + + if (this.firstLine.trim().length !== 0) { + lines.push(this.firstLine); } - let line: string = ""; - - if (this.params.length !== 0) { - line = this.lineStart + "\n"; - this.comment += this.indentLine(line); + + if (this.briefTemplate.trim().length !== 0) { + this.generateBrief(lines); + if (this.newLineAfterBrief === true) { + lines.push(this.commentPrefix); + } } - this.retVals.forEach((element: string) => { - line = this.lineStart; - line += this.commandIndicator; - line += DoxygenCommands.return + " "; // TODO: Make this customizable - line += element.trim() + "\n"; - this.comment += this.indentLine(line); - }); - } + if (this.tparamTemplate.trim().length !== 0 && this.tparams.length > 0) { + this.generateFromTemplate(lines, this.tparamTemplate, this.tparams); + if (this.newLineAfterTParams === true) { + lines.push(this.commentPrefix); + } + } - protected generateEnd() { - let line: string = " "; // TODO: Make this customizable - line += this.endComment; - this.comment += this.indentLine(line); - } + if (this.paramTemplate.trim().length !== 0 && this.params.length > 0) { + this.generateFromTemplate(lines, this.paramTemplate, this.params); + if (this.newLineAfterParams === true) { + lines.push(this.commentPrefix); + } + } - protected generateComment() { - this.generateBrief(); - this.comment += "\n"; - this.generateDetailed(); - this.comment += "\n"; - if (this.params.length !== 0) { // Only if we have parameters - this.generateParams(); + if (this.returnTemplate.trim().length !== 0 && this.retVals.length > 0) { + this.generateFromTemplate(lines, this.returnTemplate, this.retVals); } - if (this.retVals.length !== 0) { // Only if we have return values - this.generateReturn(); + + if (this.lastLine.trim().length !== 0) { + lines.push(this.lastLine); } - this.generateEnd(); + + const comment: string = lines.join("\n" + this.getIndentation()); + return comment; } - protected setCursor(line: number, character: number) { - const indentLen: number = this.indentLine("").length; + protected setCursorToBrief(line: number, character: number) { + // If there was a first line defined the brief is on the next line. + if (this.firstLine.trim().length !== 0) { + line++; + } + + character += this.commentPrefix.length + this.briefTemplate.length; + const move: Selection = new Selection(line, character, line, character); this.activeEditor.selection = move; } diff --git a/src/DocGen/DocGen.ts b/src/DocGen/DocGen.ts index 9de9d41..40ea205 100644 --- a/src/DocGen/DocGen.ts +++ b/src/DocGen/DocGen.ts @@ -1,19 +1,10 @@ -/** - * Contains the supported doxygen commands - * - * @export - * @enum {number} - */ -export enum DoxygenCommands { - brief = "brief", - return = "return", - param = "param", - detailed = "(Detailed description)", -} +import { Range } from "vscode"; + export interface IDocGen { /** - * Generate documentation string and write it to the active editor + * @brief Generate documentation string and write it to the active editor + * @param {Range} rangeToReplace Range to replace with the generated comment. */ - GenerateDoc(); + GenerateDoc(rangeToReplace: Range); } -- cgit v1.2.3 From cc0d69edcd362c1abde9d0005c70d8e3692395bc Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 02:26:22 +0200 Subject: -- Fixed tslint issues. -- Added config parameter to add type information to return DoxyGen parameter. --- src/DocGen/CGen.ts | 49 ++++++++++++++++++++++++++++++++----------------- src/DocGen/DocGen.ts | 1 - 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 97ba12e..d4a1966 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -9,6 +9,7 @@ export default class CGen implements IDocGen { protected newLineAfterBrief: boolean; protected newLineAfterParams: boolean; protected newLineAfterTParams: boolean; + protected includeTypeAtReturn: boolean; protected briefTemplate: string; protected paramTemplate: string; protected tparamTemplate: string; @@ -29,7 +30,14 @@ export default class CGen implements IDocGen { * @param {string[]} tparam The template parameter names of the method extracted by the parser. * @param {string[]} returnVals The return values extracted by the parser */ - public constructor(actEdit: TextEditor, cursorPosition: Position, param: string[], tparam: string[], returnVals: string[]) { + public constructor( + actEdit: TextEditor, + cursorPosition: + Position, + param: string[], + tparam: string[], + returnVals: string[] + ) { this.activeEditor = actEdit; this.position = cursorPosition; this.templateReplaceString = "{param}"; @@ -57,17 +65,20 @@ export default class CGen implements IDocGen { Implementation ***************************************************************************/ - protected readConfig() { - this.firstLine = workspace.getConfiguration(ConfigType.generic).get(Config.firstLine, ""); - this.commentPrefix = workspace.getConfiguration(ConfigType.generic).get(Config.commentPrefix, ""); - this.lastLine = workspace.getConfiguration(ConfigType.generic).get(Config.lastLine, ""); - this.newLineAfterBrief = workspace.getConfiguration(ConfigType.generic).get(Config.newLineAfterBrief, true); - this.newLineAfterParams = workspace.getConfiguration(ConfigType.generic).get(Config.newLineAfterParams, false); - this.newLineAfterTParams = workspace.getConfiguration(ConfigType.generic).get(Config.newLineAfterTParams, false); - this.briefTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.briefTemplate, ""); - this.paramTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.paramTemplate, ""); - this.tparamTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.tparamTemplate, ""); - this.returnTemplate = workspace.getConfiguration(ConfigType.generic).get(Config.returnTemplate, ""); + protected readConfig() { + const getCfg = workspace.getConfiguration; + + this.firstLine = getCfg(ConfigType.generic).get(Config.firstLine, ""); + this.commentPrefix = getCfg(ConfigType.generic).get(Config.commentPrefix, ""); + this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, ""); + this.newLineAfterBrief = getCfg(ConfigType.generic).get(Config.newLineAfterBrief, true); + this.newLineAfterParams = getCfg(ConfigType.generic).get(Config.newLineAfterParams, false); + this.newLineAfterTParams = getCfg(ConfigType.generic).get(Config.newLineAfterTParams, false); + this.includeTypeAtReturn = getCfg(ConfigType.generic).get(Config.includeTypeAtReturn, false); + this.briefTemplate = getCfg(ConfigType.generic).get(Config.briefTemplate, ""); + this.paramTemplate = getCfg(ConfigType.generic).get(Config.paramTemplate, ""); + this.tparamTemplate = getCfg(ConfigType.generic).get(Config.tparamTemplate, ""); + this.returnTemplate = getCfg(ConfigType.generic).get(Config.returnTemplate, ""); } protected getIndentation(): string { @@ -105,11 +116,11 @@ export default class CGen implements IDocGen { protected generateComment(): string { let lines: string[] = []; - + if (this.firstLine.trim().length !== 0) { lines.push(this.firstLine); } - + if (this.briefTemplate.trim().length !== 0) { this.generateBrief(lines); if (this.newLineAfterBrief === true) { @@ -132,11 +143,15 @@ export default class CGen implements IDocGen { } if (this.returnTemplate.trim().length !== 0 && this.retVals.length > 0) { + if (this.includeTypeAtReturn === false) { + this.retVals = this.retVals.map(t => t === "true" || t === "false" ? t : ""); + } + this.generateFromTemplate(lines, this.returnTemplate, this.retVals); } if (this.lastLine.trim().length !== 0) { - lines.push(this.lastLine); + lines.push(this.lastLine); } const comment: string = lines.join("\n" + this.getIndentation()); @@ -148,9 +163,9 @@ export default class CGen implements IDocGen { if (this.firstLine.trim().length !== 0) { line++; } - + character += this.commentPrefix.length + this.briefTemplate.length; - + const move: Selection = new Selection(line, character, line, character); this.activeEditor.selection = move; } diff --git a/src/DocGen/DocGen.ts b/src/DocGen/DocGen.ts index 40ea205..1b5b1e1 100644 --- a/src/DocGen/DocGen.ts +++ b/src/DocGen/DocGen.ts @@ -1,6 +1,5 @@ import { Range } from "vscode"; - export interface IDocGen { /** * @brief Generate documentation string and write it to the active editor -- cgit v1.2.3 From df8f38308b7871f2790b5b2cc466f7ce2add4362 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 02:32:52 +0200 Subject: -- Fixed tslint issues v2 --- src/DocGen/CGen.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index d4a1966..72bcfe0 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -1,6 +1,6 @@ -import { Position, Range, Selection, TextEditor, TextLine, WorkspaceEdit, workspace } from "vscode"; -import { IDocGen } from "./DocGen"; +import { Position, Range, Selection, TextEditor, TextLine, workspace, WorkspaceEdit } from "vscode"; import { Config, ConfigType } from "../Config"; +import { IDocGen } from "./DocGen"; export default class CGen implements IDocGen { protected firstLine: string; @@ -31,12 +31,12 @@ export default class CGen implements IDocGen { * @param {string[]} returnVals The return values extracted by the parser */ public constructor( - actEdit: TextEditor, - cursorPosition: - Position, - param: string[], - tparam: string[], - returnVals: string[] + actEdit: TextEditor, + cursorPosition: + Position, + param: string[], + tparam: string[], + returnVals: string[], ) { this.activeEditor = actEdit; this.position = cursorPosition; @@ -65,9 +65,9 @@ export default class CGen implements IDocGen { Implementation ***************************************************************************/ - protected readConfig() { + protected readConfig() { const getCfg = workspace.getConfiguration; - + this.firstLine = getCfg(ConfigType.generic).get(Config.firstLine, ""); this.commentPrefix = getCfg(ConfigType.generic).get(Config.commentPrefix, ""); this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, ""); @@ -115,7 +115,7 @@ export default class CGen implements IDocGen { } protected generateComment(): string { - let lines: string[] = []; + const lines: string[] = []; if (this.firstLine.trim().length !== 0) { lines.push(this.firstLine); @@ -144,7 +144,7 @@ export default class CGen implements IDocGen { if (this.returnTemplate.trim().length !== 0 && this.retVals.length > 0) { if (this.includeTypeAtReturn === false) { - this.retVals = this.retVals.map(t => t === "true" || t === "false" ? t : ""); + this.retVals = this.retVals.map((t) => t === "true" || t === "false" ? t : ""); } this.generateFromTemplate(lines, this.returnTemplate, this.retVals); -- cgit v1.2.3 From a9cc9c28dbff2048ffb99c04b4c8f3271c48e2d8 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 03:24:28 +0200 Subject: -- Fixed issue in setting the cursor if no brief was specified. Cursor is new set to the first DoxyGen command in the comment. --- src/DocGen/CGen.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 72bcfe0..e281c45 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -57,8 +57,8 @@ export default class CGen implements IDocGen { editBuilder.replace(rangeToReplace, comment); // Insert the comment }); - // Set cursor after brief command - this.setCursorToBrief(rangeToReplace.start.line, rangeToReplace.start.character); + // Set cursor to first DoxyGen command. + this.moveCursurToFirstDoxyCommand(comment, rangeToReplace.start.line, rangeToReplace.start.character); } /*************************************************************************** @@ -158,15 +158,25 @@ export default class CGen implements IDocGen { return comment; } - protected setCursorToBrief(line: number, character: number) { - // If there was a first line defined the brief is on the next line. + protected moveCursurToFirstDoxyCommand(comment: string, baseLine: number, baseCharacter) { + // Find first offset of a new line in the comment. Since that's when the line where the first param starts. + let line: number = baseLine; + let character: number = comment.indexOf("\n"); + + // If a first line is included find the 2nd line with a newline. if (this.firstLine.trim().length !== 0) { line++; + const oldCharacter: number = character; + character = comment.indexOf("\n", oldCharacter + 1) - oldCharacter; } - character += this.commentPrefix.length + this.briefTemplate.length; + // If newline is not found means no first param was found so Set to base position. + if (character < 0) { + line = baseLine; + character = baseCharacter; + } - const move: Selection = new Selection(line, character, line, character); - this.activeEditor.selection = move; + const moveTo: Position = new Position(line, character); + this.activeEditor.selection = new Selection(moveTo, moveTo); } } -- cgit v1.2.3 From d46ea00283644ff3f222854c02f9d95a49b91e2e Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 03:33:01 +0200 Subject: -- Removed unnecesary member variable. --- src/DocGen/CGen.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index e281c45..0b02d09 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -18,7 +18,7 @@ export default class CGen implements IDocGen { protected templateReplaceString: string; protected activeEditor: TextEditor; - protected position: Position; + protected retVals: string[]; protected params: string[]; protected tparams: string[]; @@ -39,7 +39,6 @@ export default class CGen implements IDocGen { returnVals: string[], ) { this.activeEditor = actEdit; - this.position = cursorPosition; this.templateReplaceString = "{param}"; this.params = param; this.tparams = tparam; -- cgit v1.2.3 From bb8524924007367b331a1bac27808f2d9796dc55 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 03:37:26 +0200 Subject: -- Added defaults to configuration reader in CGen. --- src/DocGen/CGen.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 0b02d09..0f8ce52 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -67,17 +67,17 @@ export default class CGen implements IDocGen { protected readConfig() { const getCfg = workspace.getConfiguration; - this.firstLine = getCfg(ConfigType.generic).get(Config.firstLine, ""); - this.commentPrefix = getCfg(ConfigType.generic).get(Config.commentPrefix, ""); - this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, ""); + this.firstLine = getCfg(ConfigType.generic).get(Config.firstLine, "/**"); + this.commentPrefix = getCfg(ConfigType.generic).get(Config.commentPrefix, " * "); + this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, "**/"); this.newLineAfterBrief = getCfg(ConfigType.generic).get(Config.newLineAfterBrief, true); this.newLineAfterParams = getCfg(ConfigType.generic).get(Config.newLineAfterParams, false); this.newLineAfterTParams = getCfg(ConfigType.generic).get(Config.newLineAfterTParams, false); this.includeTypeAtReturn = getCfg(ConfigType.generic).get(Config.includeTypeAtReturn, false); - this.briefTemplate = getCfg(ConfigType.generic).get(Config.briefTemplate, ""); - this.paramTemplate = getCfg(ConfigType.generic).get(Config.paramTemplate, ""); - this.tparamTemplate = getCfg(ConfigType.generic).get(Config.tparamTemplate, ""); - this.returnTemplate = getCfg(ConfigType.generic).get(Config.returnTemplate, ""); + this.briefTemplate = getCfg(ConfigType.generic).get(Config.briefTemplate, "@brief "); + this.paramTemplate = getCfg(ConfigType.generic).get(Config.paramTemplate, "@param {param} "); + this.tparamTemplate = getCfg(ConfigType.generic).get(Config.tparamTemplate, "@tparam {param} "); + this.returnTemplate = getCfg(ConfigType.generic).get(Config.returnTemplate, "@return {param} "); } protected getIndentation(): string { @@ -169,7 +169,7 @@ export default class CGen implements IDocGen { character = comment.indexOf("\n", oldCharacter + 1) - oldCharacter; } - // If newline is not found means no first param was found so Set to base position. + // If newline is not found means no first param was found so Set to base line before the newline. if (character < 0) { line = baseLine; character = baseCharacter; -- cgit v1.2.3 From 87ca9071ad68251156fa1fab5fc60603309a4f32 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 03:38:13 +0200 Subject: -- Fixed bad newline in constructor of CGen. --- src/DocGen/CGen.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 0f8ce52..edeb152 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -32,8 +32,7 @@ export default class CGen implements IDocGen { */ public constructor( actEdit: TextEditor, - cursorPosition: - Position, + cursorPosition: Position, param: string[], tparam: string[], returnVals: string[], -- cgit v1.2.3 From d78b9876918ce8d65876968ee120b2144178af32 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 13:23:50 +0200 Subject: -- Fixed various issues that came out of the pull request review. --- src/DocGen/CGen.ts | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index edeb152..26d5754 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -4,7 +4,7 @@ import { IDocGen } from "./DocGen"; export default class CGen implements IDocGen { protected firstLine: string; - protected commentPrefix: string; + protected prefix: string; protected lastLine: string; protected newLineAfterBrief: boolean; protected newLineAfterParams: boolean; @@ -15,7 +15,8 @@ export default class CGen implements IDocGen { protected tparamTemplate: string; protected returnTemplate: string; - protected templateReplaceString: string; + protected templateParamReplace: string; + protected templateTypeReplace: string; protected activeEditor: TextEditor; @@ -38,7 +39,8 @@ export default class CGen implements IDocGen { returnVals: string[], ) { this.activeEditor = actEdit; - this.templateReplaceString = "{param}"; + this.templateParamReplace = "{param}"; + this.templateTypeReplace = "{type}"; this.params = param; this.tparams = tparam; this.retVals = returnVals; @@ -67,8 +69,8 @@ export default class CGen implements IDocGen { const getCfg = workspace.getConfiguration; this.firstLine = getCfg(ConfigType.generic).get(Config.firstLine, "/**"); - this.commentPrefix = getCfg(ConfigType.generic).get(Config.commentPrefix, " * "); - this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, "**/"); + this.prefix = getCfg(ConfigType.generic).get(Config.prefix, " * "); + this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, " */"); this.newLineAfterBrief = getCfg(ConfigType.generic).get(Config.newLineAfterBrief, true); this.newLineAfterParams = getCfg(ConfigType.generic).get(Config.newLineAfterParams, false); this.newLineAfterTParams = getCfg(ConfigType.generic).get(Config.newLineAfterTParams, false); @@ -76,7 +78,7 @@ export default class CGen implements IDocGen { this.briefTemplate = getCfg(ConfigType.generic).get(Config.briefTemplate, "@brief "); this.paramTemplate = getCfg(ConfigType.generic).get(Config.paramTemplate, "@param {param} "); this.tparamTemplate = getCfg(ConfigType.generic).get(Config.tparamTemplate, "@tparam {param} "); - this.returnTemplate = getCfg(ConfigType.generic).get(Config.returnTemplate, "@return {param} "); + this.returnTemplate = getCfg(ConfigType.generic).get(Config.returnTemplate, "@return {type} "); } protected getIndentation(): string { @@ -94,20 +96,20 @@ export default class CGen implements IDocGen { return stringToIndent; } - protected getTemplatedString(template: string, param: string): string { - return template.replace(this.templateReplaceString, param); + protected getTemplatedString(replace: string, template: string, param: string): string { + return template.replace(replace, param); } protected generateBrief(lines: string[]) { - lines.push(this.commentPrefix + this.briefTemplate); + lines.push(this.prefix + this.briefTemplate); } - protected generateFromTemplate(lines: string[], template: string, templateWith: string[]) { + protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) { let line: string = ""; templateWith.forEach((element: string) => { - line = this.commentPrefix; - line += this.getTemplatedString(template, element); + line = this.prefix; + line += this.getTemplatedString(replace, template, element); lines.push(line); }); } @@ -122,21 +124,21 @@ export default class CGen implements IDocGen { if (this.briefTemplate.trim().length !== 0) { this.generateBrief(lines); if (this.newLineAfterBrief === true) { - lines.push(this.commentPrefix); + lines.push(this.prefix); } } if (this.tparamTemplate.trim().length !== 0 && this.tparams.length > 0) { - this.generateFromTemplate(lines, this.tparamTemplate, this.tparams); + this.generateFromTemplate(lines, this.templateParamReplace, this.tparamTemplate, this.tparams); if (this.newLineAfterTParams === true) { - lines.push(this.commentPrefix); + lines.push(this.prefix); } } if (this.paramTemplate.trim().length !== 0 && this.params.length > 0) { - this.generateFromTemplate(lines, this.paramTemplate, this.params); + this.generateFromTemplate(lines, this.templateParamReplace, this.paramTemplate, this.params); if (this.newLineAfterParams === true) { - lines.push(this.commentPrefix); + lines.push(this.prefix); } } @@ -145,7 +147,7 @@ export default class CGen implements IDocGen { this.retVals = this.retVals.map((t) => t === "true" || t === "false" ? t : ""); } - this.generateFromTemplate(lines, this.returnTemplate, this.retVals); + this.generateFromTemplate(lines, this.templateTypeReplace, this.returnTemplate, this.retVals); } if (this.lastLine.trim().length !== 0) { -- cgit v1.2.3 From 32baa67d95609fc2b0f20c582fe152eeee98ff35 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 13:29:28 +0200 Subject: -- Fixed issues from review. --- src/DocGen/CGen.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/DocGen') diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 26d5754..c2750ee 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -4,7 +4,7 @@ import { IDocGen } from "./DocGen"; export default class CGen implements IDocGen { protected firstLine: string; - protected prefix: string; + protected commentPrefix: string; protected lastLine: string; protected newLineAfterBrief: boolean; protected newLineAfterParams: boolean; @@ -69,7 +69,7 @@ export default class CGen implements IDocGen { const getCfg = workspace.getConfiguration; this.firstLine = getCfg(ConfigType.generic).get(Config.firstLine, "/**"); - this.prefix = getCfg(ConfigType.generic).get(Config.prefix, " * "); + this.commentPrefix = getCfg(ConfigType.generic).get(Config.commentPrefix, " * "); this.lastLine = getCfg(ConfigType.generic).get(Config.lastLine, " */"); this.newLineAfterBrief = getCfg(ConfigType.generic).get(Config.newLineAfterBrief, true); this.newLineAfterParams = getCfg(ConfigType.generic).get(Config.newLineAfterParams, false); @@ -101,14 +101,14 @@ export default class CGen implements IDocGen { } protected generateBrief(lines: string[]) { - lines.push(this.prefix + this.briefTemplate); + lines.push(this.commentPrefix + this.briefTemplate); } protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) { let line: string = ""; templateWith.forEach((element: string) => { - line = this.prefix; + line = this.commentPrefix; line += this.getTemplatedString(replace, template, element); lines.push(line); }); @@ -124,21 +124,21 @@ export default class CGen implements IDocGen { if (this.briefTemplate.trim().length !== 0) { this.generateBrief(lines); if (this.newLineAfterBrief === true) { - lines.push(this.prefix); + lines.push(this.commentPrefix); } } if (this.tparamTemplate.trim().length !== 0 && this.tparams.length > 0) { this.generateFromTemplate(lines, this.templateParamReplace, this.tparamTemplate, this.tparams); if (this.newLineAfterTParams === true) { - lines.push(this.prefix); + lines.push(this.commentPrefix); } } if (this.paramTemplate.trim().length !== 0 && this.params.length > 0) { this.generateFromTemplate(lines, this.templateParamReplace, this.paramTemplate, this.params); if (this.newLineAfterParams === true) { - lines.push(this.prefix); + lines.push(this.commentPrefix); } } -- cgit v1.2.3