summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2018-03-01 18:07:26 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-03-02 20:24:28 +0100
commitf41d471874c07e78a6541994b09e9f8bf751bfe5 (patch)
tree118c2ab8a3ec704742632a9c9c4a35ed5e7904ed
parent38e3c4c2cf3feb2a73226a295d039fe907b044af (diff)
downloaddoxdocgen-f41d471874c07e78a6541994b09e9f8bf751bfe5.tar.gz
Make smart text configurable
-rw-r--r--package.json15
-rw-r--r--src/Config.ts6
-rw-r--r--src/Lang/Cpp/CppDocGen.ts28
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<string>("dateTemplate", values.dateTemplate);
values.dateFormat = cfg.get<string>("dateFormat", values.dateFormat);
values.fileOrder = cfg.get<string[]>("fileOrder", values.fileOrder);
+ values.ctorText = cfg.get<string>("ctorText", values.ctorText);
+ values.dtorText = cfg.get<string>("dtorText", values.dtorText);
+ values.generateSmartText = cfg.get<boolean>("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);
}
}