summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2018-02-24 10:57:22 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-02-25 01:58:38 +0100
commitf928a1049c6582e2fbb044676c5bbca89d9b7e33 (patch)
treebd8cf6d766c495a9a737e709167f62c02f59b02a
parentd0b9d1868dc91aae5b79b414aaa51ab7100e2b60 (diff)
downloaddoxdocgen-f928a1049c6582e2fbb044676c5bbca89d9b7e33.tar.gz
Generate description of file
Fix #51
-rw-r--r--package.json10
-rw-r--r--src/Config.ts5
-rw-r--r--src/Lang/Cpp/CppDocGen.ts42
-rw-r--r--src/Lang/Cpp/CppParser.ts34
4 files changed, 77 insertions, 14 deletions
diff --git a/package.json b/package.json
index e8000a3..d19ff9e 100644
--- a/package.json
+++ b/package.json
@@ -88,6 +88,16 @@
"description": "How many lines the plugin should look for to find the end of the declaration. Please be aware that setting this value too low may improve the speed of comment generation but the plugin also may not correctly detect all declarations or definitions anymore.",
"type": "number",
"default": 20
+ },
+ "doxdocgen.file.author": {
+ "description": "Set the style of the author tag and your name.",
+ "type": "string",
+ "default": "@author your name"
+ },
+ "doxdocgen.file.file": {
+ "description": "The template for the file parameter in DoxyGen.",
+ "type": "string",
+ "default": "@file {name}"
}
}
}
diff --git a/src/Config.ts b/src/Config.ts
index 3a98a71..9b86fc8 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -20,12 +20,15 @@ export class Config {
values.tparamTemplate = cfg.get<string>("tparamTemplate", values.tparamTemplate);
values.returnTemplate = cfg.get<string>("returnTemplate", values.returnTemplate);
values.linesToGet = cfg.get<number>("linesToGet", values.linesToGet);
+ values.authorTag = cfg.get<string>("authorTag", values.authorTag);
+ values.fileTemplate = cfg.get<string>("fileTemplate", values.fileTemplate);
return values;
}
public readonly paramTemplateReplace: string = "{param}";
public readonly typeTemplateReplace: string = "{type}";
+ public readonly nameTemplateReplace: string = "{name}";
public triggerSequence: string = "/**";
public firstLine: string = "/**";
@@ -41,4 +44,6 @@ export class Config {
public tparamTemplate: string = "@tparam {param} ";
public returnTemplate: string = "@return {type} ";
public linesToGet: number = 20;
+ public authorTag: string = "@author your name";
+ public fileTemplate: string = "@file {name}";
}
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index b98abea..83803cd 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -32,8 +32,8 @@ export default class CppDocGen implements IDocGen {
) {
this.activeEditor = actEdit;
this.cfg = cfg;
- this.func = func;
this.templateParams = templateParams;
+ this.func = func;
this.params = params;
}
@@ -41,7 +41,12 @@ export default class CppDocGen implements IDocGen {
* @inheritdoc
*/
public GenerateDoc(rangeToReplace: Range) {
- const comment: string = this.generateComment();
+ let comment: string;
+ if (this.func.name === "#include") {
+ comment = this.generateFileDescription();
+ } else {
+ comment = this.generateComment();
+ }
this.activeEditor.edit((editBuilder) => {
editBuilder.replace(rangeToReplace, comment); // Insert the comment
@@ -110,6 +115,39 @@ export default class CppDocGen implements IDocGen {
return params;
}
+ protected generateFileDescription(): string {
+ const lines: string[] = [];
+
+ if (this.cfg.firstLine.trim().length !== 0) {
+ lines.push(this.cfg.firstLine);
+ }
+
+ if (this.cfg.briefTemplate.trim().length !== 0) {
+ this.generateBrief(lines);
+ if (this.cfg.newLineAfterBrief === true) {
+ lines.push(this.cfg.commentPrefix);
+ }
+ }
+
+ lines.push(this.cfg.commentPrefix + this.cfg.authorTag);
+
+ this.generateFromTemplate(
+ lines,
+ this.cfg.nameTemplateReplace,
+ this.cfg.fileTemplate,
+ [this.activeEditor.document.fileName.replace(/^.*[\\\/]/, "")],
+ );
+
+ // todo add date to file creation
+ // lines.push(new Date().toLocaleDateString());
+
+ if (this.cfg.lastLine.trim().length !== 0) {
+ lines.push(this.cfg.lastLine);
+ }
+
+ return lines.join("\n");
+ }
+
protected generateComment(): string {
const lines: string[] = [];
diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts
index 4792e14..46f22e3 100644
--- a/src/Lang/Cpp/CppParser.ts
+++ b/src/Lang/Cpp/CppParser.ts
@@ -227,22 +227,27 @@ export default class CppParser implements ICodeParser {
} catch (err) {
// console.dir(err);
}
-
- // template parsing is simpler by using heuristics rather then CppTokenizing first.
const templateArgs: string[] = [];
- while (line.startsWith("template")) {
- const template: string = this.GetTemplate(line);
+ let args: [CppArgument, CppArgument[]] = [new CppArgument(), []];
- templateArgs.push.apply(templateArgs, this.GetArgsFromTemplate(template));
+ if (line === "#include" ||
+ (activeEdit.selection.active.line === 0 && line.length === 0)) { // head of file
+ args[0].name = "#include";
+ } else { // method
+ // template parsing is simpler by using heuristics rather then CppTokenizing first.
+ while (line.startsWith("template")) {
+ const template: string = this.GetTemplate(line);
- line = line.slice(template.length, line.length + 1).trim();
- }
+ templateArgs.push.apply(templateArgs, this.GetArgsFromTemplate(template));
- let args: [CppArgument, CppArgument[]] = [new CppArgument(), []];
- try {
- args = this.GetReturnAndArgs(line);
- } catch (err) {
- // console.dir(err);
+ line = line.slice(template.length, line.length + 1).trim();
+ }
+
+ try {
+ args = this.GetReturnAndArgs(line);
+ } catch (err) {
+ // console.dir(err);
+ }
}
return new CppDocGen(
@@ -298,6 +303,11 @@ export default class CppParser implements ICodeParser {
}
}
+ // Head of file probably
+ if (nextLineTxt.startsWith("#include")) {
+ return "#include";
+ }
+
logicalLine += "\n" + nextLineTxt;
}