From cabf19e4caa35ae010b1bab19d48ad749a959e06 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 14:11:00 +0200 Subject: Implement new VS Code interface --- src/test/tools/MockEditor.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/tools/MockEditor.ts b/src/test/tools/MockEditor.ts index 5368fb8..b739e6d 100644 --- a/src/test/tools/MockEditor.ts +++ b/src/test/tools/MockEditor.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { TextEditor } from "vscode"; +import { TextEditor, Range } from "vscode"; import MockDocument from "./MockDocument"; import MockSelection from "./MockSelection"; import MockTextEditorEdit from "./MockTextEditorEdit"; @@ -11,6 +11,7 @@ export default class MockEditor implements TextEditor { public options: vscode.TextEditorOptions; public viewColumn?: vscode.ViewColumn; public editBuilder: MockTextEditorEdit; + public readonly visibleRanges: Range[]; public constructor(s: MockSelection, d: MockDocument) { this.selection = s; this.document = d; -- cgit v1.2.3 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 ++++++++++++++++++++-- src/Lang/Cpp/CppParser.ts | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src') 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; + } + } } -- cgit v1.2.3 From ce440076fd969ef79439bd3e4c36ab3d32ded08a Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 14:15:23 +0200 Subject: Fix linter warning --- src/test/tools/MockEditor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/tools/MockEditor.ts b/src/test/tools/MockEditor.ts index b739e6d..aa3cf69 100644 --- a/src/test/tools/MockEditor.ts +++ b/src/test/tools/MockEditor.ts @@ -1,5 +1,5 @@ import * as vscode from "vscode"; -import { TextEditor, Range } from "vscode"; +import { Range, TextEditor } from "vscode"; import MockDocument from "./MockDocument"; import MockSelection from "./MockSelection"; import MockTextEditorEdit from "./MockTextEditorEdit"; -- cgit v1.2.3 From cd5f4ee6d59a16c5fc99c6deb681a325e0995c35 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 15:16:16 +0200 Subject: Add test for stripping trailing `*/` --- src/test/CppTests/Config.test.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts index a4c96e6..1ef2a4d 100644 --- a/src/test/CppTests/Config.test.ts +++ b/src/test/CppTests/Config.test.ts @@ -153,4 +153,9 @@ suite("C++ - Configuration Tests", () => { const result = testSetup.SetLine("int createFooObject();").GetResult(); assert.equal("/**\n * @brief Test FooObject\n * \n * @return int \n */", result); }); + + test("Remove inserted '*/' from line", () => { + const result = testSetup.SetLines(["*/", "int foo();"]).GetResult(); + assert.equal("/**\n * @brief \n * \n * @return int \n */", result); + }); }); -- cgit v1.2.3 From 2d7a744527e469397a6dce6f27d60fac4382ee53 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 22 Jun 2019 15:45:50 +0200 Subject: Release 0.4.3 (#115) * Remove now out of date notification * Set to release 0.4.3 --- src/extension.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/extension.ts b/src/extension.ts index 7a17b52..347b392 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,19 +1,12 @@ "use strict"; // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below -import * as opn from "opn"; import * as vscode from "vscode"; import CodeParserController from "./CodeParserController"; -enum ConfigChangedNotificationOptions { - CHANGED = "What's changed", - HIDE = "Don't show me again", - GLOBAL_STORAGE_KEY = "doxdocgen_hide_config_changed_notification", -} - enum Version { - CURRENT = "0.4.2", - PREVIOUS = "0.4.1", + CURRENT = "0.4.3", + PREVIOUS = "0.4.2", KEY = "doxdocgen_version", } @@ -24,31 +17,10 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(parser); - let change: boolean = false; - const version = context.globalState.get(Version.KEY); if (version === undefined) { context.globalState.update(Version.KEY, Version.CURRENT); } else if (version !== Version.CURRENT) { - change = true; context.globalState.update(Version.KEY, Version.CURRENT); } - - let notificationHideThenable: Thenable; - const active = context.globalState.get(ConfigChangedNotificationOptions.GLOBAL_STORAGE_KEY); - if (change && (active === undefined || active !== "false")) { - // tslint:disable-next-line:max-line-length - notificationHideThenable = vscode.window.showWarningMessage("DoxDocGen: Config keys have changed. Please check your config!", ConfigChangedNotificationOptions.CHANGED, ConfigChangedNotificationOptions.HIDE); - } - - if (notificationHideThenable !== undefined) { - notificationHideThenable.then((action) => { - if (action === ConfigChangedNotificationOptions.CHANGED) { - // tslint:disable-next-line:max-line-length - opn("https://github.com/christophschlosser/doxdocgen/blob/0.3.0/CHANGELOG.md#config-update"); - } else if (action === ConfigChangedNotificationOptions.HIDE) { - context.globalState.update(ConfigChangedNotificationOptions.GLOBAL_STORAGE_KEY, "false"); - } - }); - } } -- cgit v1.2.3