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 | |
| parent | cabf19e4caa35ae010b1bab19d48ad749a959e06 (diff) | |
| download | doxdocgen-c66cc5c25d8824ade69b91129a842666bf0cf13f.tar.gz | |
Fix autogenerated close comment
| -rw-r--r-- | src/Lang/Cpp/CppDocGen.ts | 22 | ||||
| -rw-r--r-- | src/Lang/Cpp/CppParser.ts | 18 |
2 files changed, 37 insertions, 3 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); } /*************************************************************************** diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 37c36eb..ca5edbb 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -111,6 +111,8 @@ export default class CppParser implements ICodeParser { private casingType: CasingType; + private vscodeAutoGeneratedComment: boolean; + constructor(cfg: Config) { this.cfg = cfg; @@ -301,6 +303,7 @@ export default class CppParser implements ICodeParser { this.specialCase = SpecialCase.none; this.commentType = CommentType.method; + this.vscodeAutoGeneratedComment = false; } /** @@ -369,6 +372,7 @@ export default class CppParser implements ICodeParser { this.specialCase, this.commentType, this.casingType, + this.vscodeAutoGeneratedComment, ); } @@ -421,7 +425,9 @@ export default class CppParser implements ICodeParser { return ""; } - logicalLine += "\n" + nextLineTxt; + if (!this.isVsCodeAutoComplete(nextLineTxt)) { + logicalLine += "\n" + nextLineTxt; + } } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); @@ -799,4 +805,14 @@ export default class CppParser implements ICodeParser { return args; } + + private isVsCodeAutoComplete(line: string): boolean { + switch (line) { + case "*/": + this.vscodeAutoGeneratedComment = true; + return true; + default: + return false; + } + } } |