diff options
| author | to-s <tobias.weber@enisyst.de> | 2020-10-10 14:53:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-10 20:53:58 +0200 |
| commit | 8b29e605b76bf0f79685be511e60ff0d64a2375d (patch) | |
| tree | e498c7d8e2b0a42bd8e7cf2e6a52b4924b4fcc64 | |
| parent | 175bd0d5bb123a99f7de91d6045a0a25f670dd65 (diff) | |
| download | doxdocgen-8b29e605b76bf0f79685be511e60ff0d64a2375d.tar.gz | |
Added file description in first line (#183)
* Added file description in first line
Due to https://github.com/cschlosser/doxdocgen/issues/141
* Added addIndent flag to SetLines()
Co-authored-by: Christoph Schlosser <2466365+cschlosser@users.noreply.github.com>
| -rw-r--r-- | src/Lang/Cpp/CppParser.ts | 9 | ||||
| -rw-r--r-- | src/test/CppTests/FileDescription.test.ts | 13 | ||||
| -rw-r--r-- | src/test/CppTests/TestSetup.ts | 13 |
3 files changed, 31 insertions, 4 deletions
diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 8ed4bc8..3aad6ed 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -428,6 +428,15 @@ export default class CppParser implements ICodeParser { return ""; } else if (nextLineTxt.startsWith("#") && ! nextLineTxt.startsWith("#define")) { return ""; + } else if (nextLine.line === 2) { // Check if there where two empty lines trailing the file + if (this.activeEditor.document.lineAt(0).text === this.cfg.C.firstLine + && ( + this.activeEditor.document.lineAt(1).text === this.cfg.C.commentPrefix + || this.activeEditor.document.lineAt(1).text.trim() === "" + ) && this.activeEditor.document.lineAt(2).text.trim() === "") { + this.commentType = CommentType.file; + return ""; + } } if (this.isVsCodeAutoComplete(nextLineTxt) === true) { diff --git a/src/test/CppTests/FileDescription.test.ts b/src/test/CppTests/FileDescription.test.ts index d951efe..19f0790 100644 --- a/src/test/CppTests/FileDescription.test.ts +++ b/src/test/CppTests/FileDescription.test.ts @@ -38,6 +38,19 @@ suite("File Description Tests", () => { " * @date " + date + "\n */", result); }); + test("File description in first line", () => { + const result = testSetup.SetLines([ + "/**", + "", + "", + "struct T {", + " int i;", + "};", + ], false).GetResult(); + assert.equal("/**\n * @brief \n * \n * @file MockDocument.h\n * @author your name (you@domain.com)\n" + + " * @date " + date + "\n */", result); + }); + test("Don't generate non existing commands", () => { testSetup.cfg.File.fileOrder = ["dates"]; const result = testSetup.SetLine("").GetResult(); diff --git a/src/test/CppTests/TestSetup.ts b/src/test/CppTests/TestSetup.ts index 2e6c7f1..ad733dd 100644 --- a/src/test/CppTests/TestSetup.ts +++ b/src/test/CppTests/TestSetup.ts @@ -26,17 +26,22 @@ export default class TestSetup { return this.SetLines([method]); } - public SetLines(lines: string[]): TestSetup { + public SetLines(lines: string[], addIndent = true): TestSetup { let mockLines: MockLine[]; // Add two empty lines with just the indentation // since one is for the triggersequence line. // And the other is if the next empty line. if (lines.length > 0) { - const indent: string = lines[0].match("^\\s*")[0]; + if (addIndent === true) { + const indent: string = lines[0].match("^\\s*")[0]; - mockLines = [indent, indent].concat(lines) - .map((l) => new MockLine(l)); + mockLines = [indent, indent].concat(lines) + .map((l) => new MockLine(l)); + } else { + mockLines = lines + .map((l) => new MockLine(l)); + } } const selection: MockSelection = new MockSelection(new MockPosition(this.firstLine, 0)); |