From 4ab08d85d42d00fe689d0119eed269ed98b226c8 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 12:33:36 +0200 Subject: Fix vscodeautocomplete detection --- src/Lang/Cpp/CppParser.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index ca5edbb..35066fe 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -409,13 +409,13 @@ export default class CppParser implements ICodeParser { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { logicalLine += "\n" + nextLineTxt.slice(0, i); - return logicalLine.replace(/^\s+|\s+$/g, ""); + break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { logicalLine += "\n" + nextLineTxt.slice(0, i); - return logicalLine.replace(/^\s+|\s+$/g, ""); + break; } } @@ -425,9 +425,12 @@ export default class CppParser implements ICodeParser { return ""; } - if (!this.isVsCodeAutoComplete(nextLineTxt)) { + if (this.isVsCodeAutoComplete(nextLineTxt)) { logicalLine += "\n" + nextLineTxt; + logicalLine.replace(/\*\//g, ""); } + + return logicalLine.trim(); } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); -- cgit v1.2.3 From ab10903637ceacb95fb47003ca512925b8d7faa3 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 13:10:15 +0200 Subject: Fix tests --- src/Lang/Cpp/CppParser.ts | 2 +- src/test/CppTests/Con-AndDestructor.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 35066fe..35f551c 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -430,7 +430,7 @@ export default class CppParser implements ICodeParser { logicalLine.replace(/\*\//g, ""); } - return logicalLine.trim(); + return logicalLine.replace(/^\s+|\s+$/g, ""); } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); diff --git a/src/test/CppTests/Con-AndDestructor.test.ts b/src/test/CppTests/Con-AndDestructor.test.ts index 36e4fd6..ba60501 100644 --- a/src/test/CppTests/Con-AndDestructor.test.ts +++ b/src/test/CppTests/Con-AndDestructor.test.ts @@ -54,7 +54,7 @@ suite("C++ - Con- and Destructor Tests", () => { }); test("Deleted Destructor", () => { - const result = testSetup.SetLine("virtual ~Foo() = 0").GetResult(); + const result = testSetup.SetLine("virtual ~Foo() = 0;").GetResult(); assert.equal("/**\n * @brief \n * \n */", result); }); -- cgit v1.2.3 From e6388bf4711db2802d9cb8de5a2577b5dffafff3 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 14:02:06 +0200 Subject: Fix for real --- src/Lang/Cpp/CppParser.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 35f551c..0eb8a23 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -386,7 +386,7 @@ export default class CppParser implements ICodeParser { let nextLineTxt: string = this.activeEditor.document.lineAt(nextLine.line).text.trim(); - // VSCode may enter a * on itself, we don"t want that in our method + // VSCode may enter a * on itself, we don't want that in our method if (nextLineTxt === "*") { nextLineTxt = ""; } @@ -399,6 +399,7 @@ export default class CppParser implements ICodeParser { while (linesToGet-- > 0) { // Check for end of expression. nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); + let finalSlice = 0; // Check if method has finished if curly brace is opened while // nesting is occuring. @@ -408,13 +409,12 @@ export default class CppParser implements ICodeParser { } else if (nextLineTxt[i] === ")") { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { - logicalLine += "\n" + nextLineTxt.slice(0, i); + finalSlice = i; break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { - - logicalLine += "\n" + nextLineTxt.slice(0, i); + finalSlice = i; break; } } @@ -425,12 +425,19 @@ export default class CppParser implements ICodeParser { return ""; } - if (this.isVsCodeAutoComplete(nextLineTxt)) { - logicalLine += "\n" + nextLineTxt; + if (!this.isVsCodeAutoComplete(nextLineTxt)) { + logicalLine += "\n"; + if (finalSlice > 0) { + logicalLine += nextLineTxt.slice(0, finalSlice); + } else { + logicalLine += nextLineTxt; + } logicalLine.replace(/\*\//g, ""); } - return logicalLine.replace(/^\s+|\s+$/g, ""); + if (finalSlice > 0) { + return logicalLine.replace(/^\s+|\s+$/g, ""); + } } throw new Error("More than " + linesToGet + " lines were read from editor and no end of expression was found."); -- cgit v1.2.3 From 23e24325bac129e723537be4096f053ac3394850 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 14:03:04 +0200 Subject: Fix test lines --- src/test/CppTests/Operators.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/test/CppTests/Operators.test.ts b/src/test/CppTests/Operators.test.ts index 09f5dd4..b35cc81 100644 --- a/src/test/CppTests/Operators.test.ts +++ b/src/test/CppTests/Operators.test.ts @@ -279,22 +279,22 @@ suite("C++ - Operators Tests", () => { }); test("Implicit conversion operator", () => { - const result = testSetup.SetLine("operator int() const").GetResult(); + const result = testSetup.SetLine("operator int() const;").GetResult(); assert.equal("/**\n * @brief \n * \n * @return int \n */", result); }); test("Explicit conversion operator", () => { - const result = testSetup.SetLine("explicit operator int() const").GetResult(); + const result = testSetup.SetLine("explicit operator int() const;").GetResult(); assert.equal("/**\n * @brief \n * \n * @return int \n */", result); }); test("conversion operator to struct", () => { - const result = testSetup.SetLine("explicit operator struct foo() const").GetResult(); + const result = testSetup.SetLine("explicit operator struct foo() const;").GetResult(); assert.equal("/**\n * @brief \n * \n * @return struct foo \n */", result); }); test("conversion operator to struct pointer", () => { - const result = testSetup.SetLine("explicit operator struct foo*() const").GetResult(); + const result = testSetup.SetLine("explicit operator struct foo*() const;").GetResult(); assert.equal("/**\n * @brief \n * \n * @return struct foo* \n */", result); }); }); -- cgit v1.2.3 From 1cf0a3b9762ad5734352fa25514e50caf27ae52f Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 15:28:09 +0200 Subject: Ignore restrict keyword --- src/Lang/Cpp/CppParser.ts | 1 + src/test/CppTests/Parameters.test.ts | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 0eb8a23..c6a72fb 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -121,6 +121,7 @@ export default class CppParser implements ICodeParser { "const", "struct", "enum", + "restrict", ]; this.stripKeywords = [ diff --git a/src/test/CppTests/Parameters.test.ts b/src/test/CppTests/Parameters.test.ts index 9c99100..cfcebe8 100644 --- a/src/test/CppTests/Parameters.test.ts +++ b/src/test/CppTests/Parameters.test.ts @@ -263,6 +263,11 @@ suite("C++ - Parameters Tests", () => { assert.equal("/**\n * @brief \n * \n * @param memberPointer \n */", result); }); + test("Restrict keyword", () => { + const result = testSetup.SetLine("void some_function(char *restrict buf, const size_t buflen);").GetResult(); + assert.equal("/**\n * @brief \n * \n * @param buf \n * @param buflen \n */", result); + }); + test("Type as variable name", () => { let result = testSetup.SetLine("void MapPoint(double latitude, double longtitude) const;").GetResult(); assert.equal("/**\n * @brief \n * \n * @param latitude \n * @param longtitude \n */", result); -- cgit v1.2.3 From 6e749554cc7a47849bd63d7ec1027f084d26b505 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 16:50:54 +0200 Subject: Add arraypointers --- src/Lang/Cpp/CppParser.ts | 22 +++++++++++++++++++++- src/test/CppTests/FunctionPointer.test.ts | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index c6a72fb..2ea3c3f 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -563,6 +563,22 @@ export default class CppParser implements ICodeParser { return nodes.filter((n) => n instanceof CppParseTree).length === 2; } + private IsArrayPtr(nodes: Array) { + if (nodes.filter((n) => n instanceof CppParseTree).length === 1) { + const treeIdx = nodes.findIndex((n) => n instanceof CppParseTree); + if (treeIdx !== -1) { + const nextElem = nodes[treeIdx + 1]; + if (nextElem instanceof CppToken) { + const match = nextElem.value.match(/^\[[0-9]*\]$/g); + if (match !== undefined && match !== null) { + return match.length > 0; + } + } + } + } + return false; + } + private StripNonTypeNodes(tree: CppParseTree) { tree.nodes = tree.nodes // All strippable keywords. @@ -625,7 +641,7 @@ export default class CppParser implements ICodeParser { let cursor: CppParseTree = tree; - while (this.IsFuncPtr(cursor.nodes) === true) { + while (this.IsFuncPtr(cursor.nodes) === true || this.IsArrayPtr(cursor.nodes) === true) { cursor = cursor.nodes.find((n) => n instanceof CppParseTree) as CppParseTree; } @@ -713,6 +729,10 @@ export default class CppParser implements ICodeParser { return this.GetArgumentFromFuncPtr(copy); } + if (this.IsArrayPtr(copy.nodes) === true) { + return this.GetArgumentFromFuncPtr(copy); + } + // Handle member pointers for (let token: number = 0; token < copy.nodes.length - 1; token++) { const firstToken: CppToken = copy.nodes[token] as CppToken; diff --git a/src/test/CppTests/FunctionPointer.test.ts b/src/test/CppTests/FunctionPointer.test.ts index 7a4383c..cd318ce 100644 --- a/src/test/CppTests/FunctionPointer.test.ts +++ b/src/test/CppTests/FunctionPointer.test.ts @@ -44,4 +44,9 @@ suite("C++ - Function pointer Tests", () => { const result = testSetup.SetLine("void foo(void (SomeClass::* func)());").GetResult(); assert.equal("/**\n * @brief \n * \n * @param func \n */", result); }); + + test("Arraypointer", () => { + const result = testSetup.SetLine("void some_function(int (*table)[]);").GetResult(); + assert.equal("/**\n * @brief \n * \n * @param table \n */", result); + }); }); -- cgit v1.2.3 From fc661c98fa316e036e9a6098fd7d66f92ac1baf1 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Sat, 5 Oct 2019 15:43:55 +0200 Subject: Prepare release 0.5.1 --- src/extension.ts | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/extension.ts b/src/extension.ts index 8199845..ea7762b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -12,8 +12,8 @@ enum AlignmentNotificationOptions { } enum Version { - CURRENT = "0.5.0", - PREVIOUS = "0.4.3", + CURRENT = "0.5.1", + PREVIOUS = "0.5.0", KEY = "doxdocgen_version", } @@ -24,35 +24,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) { - if (parseInt(version.split(".")[1], 10) < 5) { - change = true; - } context.globalState.update(Version.KEY, Version.CURRENT); } - let notificationHideThenable: Thenable; - const active = context.globalState.get(AlignmentNotificationOptions.GLOBAL_STORAGE_KEY); - if (change && (active === undefined || active !== "false")) { - // tslint:disable-next-line:max-line-length - notificationHideThenable = - vscode.window.showWarningMessage("DoxDocGen: I can now align your comments", - AlignmentNotificationOptions.CHANGED, - AlignmentNotificationOptions.HIDE); - } - - if (notificationHideThenable !== undefined) { - notificationHideThenable.then((action) => { - if (action === AlignmentNotificationOptions.CHANGED) { - // tslint:disable-next-line:max-line-length - opn("https://github.com/christophschlosser/doxdocgen/blob/master/CHANGELOG.md#alignment"); - } else if (action === AlignmentNotificationOptions.HIDE) { - context.globalState.update(AlignmentNotificationOptions.GLOBAL_STORAGE_KEY, "false"); - } - }); - } - } -- cgit v1.2.3 From 3c16da1b09b4a7490e2139d1ee3b96e4ed096806 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Tue, 8 Oct 2019 19:13:55 +0200 Subject: End of declaration problem fixed If the terminating character is the first one on the next line it can cause the buffer to fill and thus produce malformed text to parse. --- src/Lang/Cpp/CppParser.ts | 7 +++++-- src/test/CppTests/Attributes.test.ts | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 2ea3c3f..3b13721 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -401,6 +401,7 @@ export default class CppParser implements ICodeParser { nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); let finalSlice = 0; + let endOfDeclaration = false; // Check if method has finished if curly brace is opened while // nesting is occuring. @@ -411,11 +412,13 @@ export default class CppParser implements ICodeParser { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { finalSlice = i; + endOfDeclaration = true; break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { finalSlice = i; + endOfDeclaration = true; break; } } @@ -428,7 +431,7 @@ export default class CppParser implements ICodeParser { if (!this.isVsCodeAutoComplete(nextLineTxt)) { logicalLine += "\n"; - if (finalSlice > 0) { + if (endOfDeclaration === true) { logicalLine += nextLineTxt.slice(0, finalSlice); } else { logicalLine += nextLineTxt; @@ -436,7 +439,7 @@ export default class CppParser implements ICodeParser { logicalLine.replace(/\*\//g, ""); } - if (finalSlice > 0) { + if (endOfDeclaration) { return logicalLine.replace(/^\s+|\s+$/g, ""); } } diff --git a/src/test/CppTests/Attributes.test.ts b/src/test/CppTests/Attributes.test.ts index bfeaef1..a6641e1 100644 --- a/src/test/CppTests/Attributes.test.ts +++ b/src/test/CppTests/Attributes.test.ts @@ -59,4 +59,9 @@ suite("C++ - Attributes Tests", () => { const result = testSetup.SetLine("constexpr int foo(int a, double& b) throw(std::except);").GetResult(); assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return constexpr int \n */", result); }); + + test("Newline in function", () => { + const result = testSetup.SetLines(["static void ResetActionState( BOOL sendNAK )", "{"]).GetResult(); + assert.equal("/**\n * @brief \n * \n * @param sendNAK \n */", result); + }); }); -- cgit v1.2.3 From a5b9a5497abd07c157c8faa5af17a3a16ffe90ad Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Tue, 8 Oct 2019 21:52:10 +0200 Subject: =?UTF-8?q?Don=E2=80=99t=20use=20unnecessary=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lang/Cpp/CppParser.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 3b13721..dcdfcba 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -400,8 +400,7 @@ export default class CppParser implements ICodeParser { while (linesToGet-- > 0) { // Check for end of expression. nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); - let finalSlice = 0; - let endOfDeclaration = false; + let finalSlice = -1; // Check if method has finished if curly brace is opened while // nesting is occuring. @@ -412,13 +411,11 @@ export default class CppParser implements ICodeParser { currentNest--; } else if (nextLineTxt[i] === "{" && currentNest === 0) { finalSlice = i; - endOfDeclaration = true; break; } else if ((nextLineTxt[i] === ";" || (nextLineTxt[i] === ":" && nextLineTxt[i - 1] !== ":" && nextLineTxt[i + 1] !== ":")) && currentNest === 0) { finalSlice = i; - endOfDeclaration = true; break; } } @@ -431,7 +428,7 @@ export default class CppParser implements ICodeParser { if (!this.isVsCodeAutoComplete(nextLineTxt)) { logicalLine += "\n"; - if (endOfDeclaration === true) { + if (finalSlice >= 0) { logicalLine += nextLineTxt.slice(0, finalSlice); } else { logicalLine += nextLineTxt; @@ -439,7 +436,7 @@ export default class CppParser implements ICodeParser { logicalLine.replace(/\*\//g, ""); } - if (endOfDeclaration) { + if (finalSlice >= 0) { return logicalLine.replace(/^\s+|\s+$/g, ""); } } -- cgit v1.2.3 From d12cfa9537790ce3489967f77de18ef52717daeb Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Tue, 8 Oct 2019 21:54:50 +0200 Subject: Release 0.5.2 --- src/extension.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/extension.ts b/src/extension.ts index ea7762b..55f7e46 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 AlignmentNotificationOptions { - CHANGED = "Show me how to do that", - HIDE = "Don't show me again", - GLOBAL_STORAGE_KEY = "doxdocgen_hide_alignment_notification", -} - enum Version { - CURRENT = "0.5.1", - PREVIOUS = "0.5.0", + CURRENT = "0.5.2", + PREVIOUS = "0.5.1", KEY = "doxdocgen_version", } -- cgit v1.2.3