From f41d471874c07e78a6541994b09e9f8bf751bfe5 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Thu, 1 Mar 2018 18:07:26 +0100 Subject: Make smart text configurable --- package.json | 15 +++++++++++++++ src/Config.ts | 6 ++++++ src/Lang/Cpp/CppDocGen.ts | 28 +++++++++++++++++++++------- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a09453d..14f61a4 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,21 @@ "description": "The order to use for the date. Valid values are shown in default setting.", "type": ["array", "string"], "default": ["brief", "file", "author", "date"] + }, + "doxdocgen.generic.ctorText": { + "description": "Smart text snippet for constructors.", + "type": "string", + "default": "Construct a new {name} object" + }, + "doxdocgen.generic.dtorText": { + "description": "Smart text snippet for destructors.", + "type": "string", + "default": "Destroy the {name} object" + }, + "doxdocgen.generic.generateSmartText": { + "description": "Decide if you want to get smart text for certain commands.", + "type": "boolean", + "default": true } } } diff --git a/src/Config.ts b/src/Config.ts index e8d7379..3c589f5 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -25,6 +25,9 @@ export class Config { values.dateTemplate = cfg.get("dateTemplate", values.dateTemplate); values.dateFormat = cfg.get("dateFormat", values.dateFormat); values.fileOrder = cfg.get("fileOrder", values.fileOrder); + values.ctorText = cfg.get("ctorText", values.ctorText); + values.dtorText = cfg.get("dtorText", values.dtorText); + values.generateSmartText = cfg.get("generateSmartText", values.generateSmartText); return values; } @@ -53,4 +56,7 @@ export class Config { public dateTemplate: string = "@date {date}"; public dateFormat: string = "YYYY-MM-DD"; public fileOrder: string[] = ["brief", "file", "author", "date"]; + public ctorText: string = "YYYY-MM-DD"; + public dtorText: string = "YYYY-MM-DD"; + public generateSmartText: boolean = true; } diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 6f3ecc7..a7994eb 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -29,6 +29,8 @@ export class CppDocGen implements IDocGen { protected specialCase: SpecialCase; protected commentType: CommentType; + protected smartTextLength: number; + /** * @param {TextEditor} actEdit Active editor window * @param {Position} cursorPosition Where the cursor of the user currently is @@ -54,16 +56,17 @@ export class CppDocGen implements IDocGen { this.params = params; this.specialCase = specialCase; this.commentType = commentType; + this.smartTextLength = 0; } /** * @inheritdoc */ public GenerateDoc(rangeToReplace: Range) { - let comment: string; + let comment: string = ""; if (this.commentType === CommentType.file) { comment = this.generateFileDescription(); - } else { + } else if (this.commentType === CommentType.method) { comment = this.generateComment(); } @@ -87,20 +90,30 @@ export class CppDocGen implements IDocGen { } protected getSmartText(): string { - // todo: Make the text customizable + if (!this.cfg.generateSmartText) { + return ""; + } switch (this.specialCase) { case SpecialCase.constructor: { if (this.func.name === null) { return ""; } else { - return "Construct a new " + this.func.name.trim() + " object"; + const str = this.getTemplatedString(this.cfg.nameTemplateReplace, + this.cfg.ctorText, + this.func.name.trim()); + this.smartTextLength = str.length; + return str; } } case SpecialCase.destructor: { if (this.func.name === null) { return ""; } else { - return "Destroy the " + this.func.name.replace("~", "").trim() + " object"; + const str = this.getTemplatedString(this.cfg.nameTemplateReplace, + this.cfg.dtorText, + this.func.name.replace("~", "").trim()); + this.smartTextLength = str.length; + return str; } } // tslint:disable-next-line:no-empty @@ -299,7 +312,8 @@ export class CppDocGen implements IDocGen { character = baseCharacter; } - const moveTo: Position = new Position(line, character); - this.activeEditor.selection = new Selection(moveTo, moveTo); + const from: Position = new Position(line, character - this.smartTextLength - 1); + const to: Position = new Position(line, character); + this.activeEditor.selection = new Selection(from, to); } } -- cgit v1.2.3