diff options
| author | Christoph Schlosser <christoph@linux.com> | 2019-06-22 14:11:12 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2019-06-22 15:30:39 +0200 |
| commit | c66cc5c25d8824ade69b91129a842666bf0cf13f (patch) | |
| tree | 22f137e8914a1ddda69cac30532f3404e7a23c83 /src/Lang/Cpp/CppDocGen.ts | |
| parent | cabf19e4caa35ae010b1bab19d48ad749a959e06 (diff) | |
| download | doxdocgen-c66cc5c25d8824ade69b91129a842666bf0cf13f.tar.gz | |
Fix autogenerated close comment
Diffstat (limited to 'src/Lang/Cpp/CppDocGen.ts')
| -rw-r--r-- | src/Lang/Cpp/CppDocGen.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 75b67af..bc5a355 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -45,6 +45,8 @@ export class CppDocGen implements IDocGen { protected smartTextLength: number; + protected vscodeAutoGeneratedComment: boolean; + /** * @param {TextEditor} actEdit Active editor window * @param {Position} cursorPosition Where the cursor of the user currently is @@ -52,6 +54,8 @@ export class CppDocGen implements IDocGen { * @param {CppArgument} func The type and name of the function to generate doxygen. * Doesn't contain anything if it is not a function. * @param {CppArgument[]} params The parameters of the function. Doesn't contain anything if it is not a function. + * @param {boolean} vscodeAutoGeneratedComment Set this to true if VS Code inserted an autogenerated comment closer + * on the next line after the comment. */ public constructor( actEdit: TextEditor, @@ -63,6 +67,7 @@ export class CppDocGen implements IDocGen { specialCase: SpecialCase, commentType: CommentType, casingType: CasingType, + vscodeAutoGeneratedComment: boolean, ) { this.activeEditor = actEdit; this.cfg = cfg; @@ -73,6 +78,7 @@ export class CppDocGen implements IDocGen { this.commentType = commentType; this.smartTextLength = 0; this.casingType = casingType; + this.vscodeAutoGeneratedComment = vscodeAutoGeneratedComment; } /** @@ -86,12 +92,24 @@ export class CppDocGen implements IDocGen { comment = this.generateComment(); } + // overwrite any autogenerated comment closer + let modifiedRangeToReplace = rangeToReplace; + if (this.vscodeAutoGeneratedComment) { + const newPos: Position = new Position( + modifiedRangeToReplace.end.line + 1, + modifiedRangeToReplace.end.character, + ); + modifiedRangeToReplace = new Range(rangeToReplace.start, newPos); + } + this.activeEditor.edit((editBuilder) => { - editBuilder.replace(rangeToReplace, comment); // Insert the comment + editBuilder.replace(modifiedRangeToReplace, comment); // Insert the comment }); // Set cursor to first DoxyGen command. - this.moveCursurToFirstDoxyCommand(comment, rangeToReplace.start.line, rangeToReplace.start.character); + this.moveCursurToFirstDoxyCommand(comment, + modifiedRangeToReplace.start.line, + modifiedRangeToReplace.start.character); } /*************************************************************************** |