summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZongyuan Zuo <eternalphane@gmail.com>2019-11-16 11:13:48 +0800
committerGitHub <noreply@github.com>2019-11-16 11:13:48 +0800
commit05fee9e8eb71c8ed1c3f6e47110040c105cd42eb (patch)
tree74a7de00fc142bcac8e93bf724553d9efd536847 /src
parent5648d5ed96d6150f14530f14df5842dc248bf4be (diff)
parentd12cfa9537790ce3489967f77de18ef52717daeb (diff)
downloaddoxdocgen-05fee9e8eb71c8ed1c3f6e47110040c105cd42eb.tar.gz
Merge branch 'master' into master
Diffstat (limited to 'src')
-rw-r--r--src/Lang/Cpp/CppParser.ts47
-rw-r--r--src/extension.ts36
-rw-r--r--src/test/CppTests/Attributes.test.ts5
-rw-r--r--src/test/CppTests/Con-AndDestructor.test.ts2
-rw-r--r--src/test/CppTests/FunctionPointer.test.ts5
-rw-r--r--src/test/CppTests/Operators.test.ts8
-rw-r--r--src/test/CppTests/Parameters.test.ts5
7 files changed, 61 insertions, 47 deletions
diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts
index ca5edbb..dcdfcba 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 = [
@@ -386,7 +387,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 +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 = -1;
// Check if method has finished if curly brace is opened while
// nesting is occuring.
@@ -408,14 +410,13 @@ export default class CppParser implements ICodeParser {
} else if (nextLineTxt[i] === ")") {
currentNest--;
} else if (nextLineTxt[i] === "{" && currentNest === 0) {
- logicalLine += "\n" + nextLineTxt.slice(0, i);
- return logicalLine.replace(/^\s+|\s+$/g, "");
+ finalSlice = i;
+ 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, "");
+ finalSlice = i;
+ break;
}
}
@@ -426,7 +427,17 @@ export default class CppParser implements ICodeParser {
}
if (!this.isVsCodeAutoComplete(nextLineTxt)) {
- logicalLine += "\n" + nextLineTxt;
+ logicalLine += "\n";
+ if (finalSlice >= 0) {
+ logicalLine += nextLineTxt.slice(0, finalSlice);
+ } else {
+ logicalLine += nextLineTxt;
+ }
+ logicalLine.replace(/\*\//g, "");
+ }
+
+ if (finalSlice >= 0) {
+ return logicalLine.replace(/^\s+|\s+$/g, "");
}
}
@@ -552,6 +563,22 @@ export default class CppParser implements ICodeParser {
return nodes.filter((n) => n instanceof CppParseTree).length === 2;
}
+ private IsArrayPtr(nodes: Array<CppToken | CppParseTree>) {
+ 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.
@@ -614,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;
}
@@ -702,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/extension.ts b/src/extension.ts
index 8199845..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.0",
- PREVIOUS = "0.4.3",
+ CURRENT = "0.5.2",
+ PREVIOUS = "0.5.1",
KEY = "doxdocgen_version",
}
@@ -24,35 +17,10 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(parser);
- let change: boolean = false;
const version = context.globalState.get<string>(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<string>;
- const active = context.globalState.get<string>(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");
- }
- });
- }
-
}
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);
+ });
});
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);
});
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);
+ });
});
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);
});
});
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);