From c66cc5c25d8824ade69b91129a842666bf0cf13f Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 14:11:12 +0200 Subject: Fix autogenerated close comment --- src/Lang/Cpp/CppDocGen.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/Lang/Cpp/CppDocGen.ts') 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); } /*************************************************************************** -- cgit v1.2.3