diff options
| author | Christoph Schlosser <christoph@linux.com> | 2018-02-25 23:26:04 +0100 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2018-03-02 20:24:28 +0100 |
| commit | 38e3c4c2cf3feb2a73226a295d039fe907b044af (patch) | |
| tree | b234d97b1e1838ea3eaa74de1020c57e77294530 /src/Lang/Cpp/CppDocGen.ts | |
| parent | ad1bf4f70264216ec80f9bf01a2c03006161d39b (diff) | |
| download | doxdocgen-38e3c4c2cf3feb2a73226a295d039fe907b044af.tar.gz | |
Suggest smart text for ctor and dtor
Diffstat (limited to 'src/Lang/Cpp/CppDocGen.ts')
| -rw-r--r-- | src/Lang/Cpp/CppDocGen.ts | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index ebfa5f5..6f3ecc7 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -6,7 +6,18 @@ import { CppArgument } from "./CppArgument"; import { CppParseTree } from "./CppParseTree"; import { CppToken, CppTokenType } from "./CppToken"; -export default class CppDocGen implements IDocGen { +export enum SpecialCase { + none, + constructor, + destructor, +} + +export enum CommentType { + method, + file, +} + +export class CppDocGen implements IDocGen { protected activeEditor: TextEditor; protected readonly cfg: Config; @@ -15,6 +26,9 @@ export default class CppDocGen implements IDocGen { protected templateParams: string[]; protected params: CppArgument[]; + protected specialCase: SpecialCase; + protected commentType: CommentType; + /** * @param {TextEditor} actEdit Active editor window * @param {Position} cursorPosition Where the cursor of the user currently is @@ -30,12 +44,16 @@ export default class CppDocGen implements IDocGen { templateParams: string[], func: CppArgument, params: CppArgument[], + specialCase: SpecialCase, + commentType: CommentType, ) { this.activeEditor = actEdit; this.cfg = cfg; this.templateParams = templateParams; this.func = func; this.params = params; + this.specialCase = specialCase; + this.commentType = commentType; } /** @@ -43,7 +61,7 @@ export default class CppDocGen implements IDocGen { */ public GenerateDoc(rangeToReplace: Range) { let comment: string; - if (this.func.name === "#include") { + if (this.commentType === CommentType.file) { comment = this.generateFileDescription(); } else { comment = this.generateComment(); @@ -68,8 +86,33 @@ export default class CppDocGen implements IDocGen { return template.replace(replace, param); } + protected getSmartText(): string { + // todo: Make the text customizable + switch (this.specialCase) { + case SpecialCase.constructor: { + if (this.func.name === null) { + return ""; + } else { + return "Construct a new " + this.func.name.trim() + " object"; + } + } + case SpecialCase.destructor: { + if (this.func.name === null) { + return ""; + } else { + return "Destroy the " + this.func.name.replace("~", "").trim() + " object"; + } + } + // tslint:disable-next-line:no-empty + case SpecialCase.none: + default: { + return ""; + } + } + } + protected generateBrief(lines: string[]) { - lines.push(this.cfg.commentPrefix + this.cfg.briefTemplate); + lines.push(this.cfg.commentPrefix + this.cfg.briefTemplate + this.getSmartText()); } protected generateFromTemplate(lines: string[], replace: string, template: string, templateWith: string[]) { |