diff options
| author | Rowan Goemans <RB.Goemans@student.han.nl> | 2017-10-15 02:26:22 +0200 |
|---|---|---|
| committer | Rowan Goemans <RB.Goemans@student.han.nl> | 2017-10-15 02:26:22 +0200 |
| commit | cc0d69edcd362c1abde9d0005c70d8e3692395bc (patch) | |
| tree | 2d991729ec43b411dcbde82a4dd0424cdd0b9771 /src | |
| parent | 0ebfa5bd12e529d8febe73c85d3bf48c4d4997e8 (diff) | |
| download | doxdocgen-cc0d69edcd362c1abde9d0005c70d8e3692395bc.tar.gz | |
-- Fixed tslint issues.
-- Added config parameter to add type information to return DoxyGen parameter.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CodeParser/CParser.ts | 31 | ||||
| -rw-r--r-- | src/CodeParser/CodeParserController.ts | 25 | ||||
| -rw-r--r-- | src/Config.ts | 1 | ||||
| -rw-r--r-- | src/DocGen/CGen.ts | 49 | ||||
| -rw-r--r-- | src/DocGen/DocGen.ts | 1 |
5 files changed, 70 insertions, 37 deletions
diff --git a/src/CodeParser/CParser.ts b/src/CodeParser/CParser.ts index 12ed169..77b01eb 100644 --- a/src/CodeParser/CParser.ts +++ b/src/CodeParser/CParser.ts @@ -25,28 +25,33 @@ export default class CParser implements ICodeParser { const activeLine: TextLine = this.activeEditor.document.lineAt(this.activeEditor.selection.active.line); - const method: string = this.getMethodText(); + const line: string = this.getLogicalLine(); // Not a method - if (method.length === 0) { + if (line.length === 0) { return null; } - const returnValue: string[] = this.getReturn(method); + const returnValue: string[] = this.getReturn(line); - const params: string[] = this.getParams(method); - const tparams: string[] = this.getTemplateParams(method); + const params: string[] = this.getParams(line); + const tparams: string[] = this.getTemplateParams(line); - const cppGenerator: IDocGen = new Generator(this.activeEditor, this.activeSelection, params, tparams, returnValue); + const cppGenerator: IDocGen = new Generator( + this.activeEditor, + this.activeSelection, + params, + tparams, + returnValue + ); return cppGenerator; } /*************************************************************************** Implementation ***************************************************************************/ - - protected getMethodText(): string { - let method: string = ""; + protected getLogicalLine(): string { + let logicalLine: string = ""; let nextLine: Position = new Position(this.activeSelection.line + 1, this.activeSelection.character); @@ -62,7 +67,7 @@ export default class CParser implements ICodeParser { nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); } - method += nextLineTxt; + logicalLine += nextLineTxt; // Get method end line while (nextLineTxt.indexOf(")") === -1 && @@ -70,15 +75,15 @@ export default class CParser implements ICodeParser { nextLine = new Position(nextLine.line + 1, nextLine.character); nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); - method += " " + nextLineTxt; + logicalLine += " " + nextLineTxt; } // Not a method but some code in the file - if (method.indexOf(")") === -1) { + if (logicalLine.indexOf(")") === -1) { return ""; } - return method; + return logicalLine; } protected getReturn(method: string): string[] { diff --git a/src/CodeParser/CodeParserController.ts b/src/CodeParser/CodeParserController.ts index 0a80e77..054aa38 100644 --- a/src/CodeParser/CodeParserController.ts +++ b/src/CodeParser/CodeParserController.ts @@ -1,4 +1,13 @@ -import { Disposable, Position, Range, TextDocumentContentChangeEvent, TextEditor, TextLine, window, workspace } from "vscode"; +import { + Disposable, + Position, + Range, + TextDocumentContentChangeEvent, + TextEditor, + TextLine, + window, + workspace +} from "vscode"; import { Config, ConfigType } from "../Config"; import CodeParser from "./CodeParser"; import CParser from "./CParser"; @@ -51,7 +60,9 @@ export default class CodeParserController { ***************************************************************************/ private readConfig() { - this.triggerSequence = workspace.getConfiguration(ConfigType.generic).get<string>(Config.triggerSequence, "/**"); + this.triggerSequence = workspace + .getConfiguration(ConfigType.generic) + .get<string>(Config.triggerSequence, "/**"); } private check(activeEditor: TextEditor, event: TextDocumentContentChangeEvent): boolean { @@ -63,13 +74,12 @@ export default class CodeParserController { const activeChar: string = activeLine.text.charAt(activeSelection.character); const startsWith: boolean = event.text.startsWith("\n") || event.text.startsWith("\r\n"); - // Check if enter was pressed. Note the ! + // Check if enter was pressed. Note the ! if (!((activeChar === "") && startsWith)) { return false; } const cont: string = activeLine.text.trim(); - let found: boolean = false; return this.triggerSequence === cont; } @@ -96,10 +106,13 @@ export default class CodeParserController { } const currentPos: Position = window.activeTextEditor.selection.active; - const startReplace: Position = new Position(currentPos.line, currentPos.character - this.triggerSequence.length); + const startReplace: Position = new Position( + currentPos.line, + currentPos.character - this.triggerSequence.length + ); let endReplace: Position = new Position(currentPos.line, currentPos.character); - const nextLineText: String = window.activeTextEditor.document.lineAt(endReplace.line + 1).text; + const nextLineText: string = window.activeTextEditor.document.lineAt(endReplace.line + 1).text; // VSCode may enter a * on itself, we don't want that in our comment. if (nextLineText.trim() === "*") { endReplace = new Position(currentPos.line + 1, nextLineText.length); diff --git a/src/Config.ts b/src/Config.ts index f8011c3..3cc78fb 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -10,6 +10,7 @@ export enum Config { newLineAfterBrief = "newLineAfterBrief", newLineAfterParams = "newLineAfterParams", newLineAfterTParams = "newLineAfterTParams", + includeTypeAtReturn = "includeTypeAtReturn", briefTemplate = "briefTemplate", paramTemplate = "paramTemplate", tparamTemplate = "tparamTemplate", diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts index 97ba12e..d4a1966 100644 --- a/src/DocGen/CGen.ts +++ b/src/DocGen/CGen.ts @@ -9,6 +9,7 @@ export default class CGen implements IDocGen { protected newLineAfterBrief: boolean; protected newLineAfterParams: boolean; protected newLineAfterTParams: boolean; + protected includeTypeAtReturn: boolean; protected briefTemplate: string; protected paramTemplate: string; protected tparamTemplate: string; @@ -29,7 +30,14 @@ export default class CGen implements IDocGen { * @param {string[]} tparam The template parameter names of the method extracted by the parser. * @param {string[]} returnVals The return values extracted by the parser */ - public constructor(actEdit: TextEditor, cursorPosition: Position, param: string[], tparam: string[], returnVals: string[]) { + public constructor( + actEdit: TextEditor, + cursorPosition: + Position, + param: string[], + tparam: string[], + returnVals: string[] + ) { this.activeEditor = actEdit; this.position = cursorPosition; this.templateReplaceString = "{param}"; @@ -57,17 +65,20 @@ export default class CGen implements IDocGen { Implementation ***************************************************************************/ - protected readConfig() { - this.firstLine = workspace.getConfiguration(ConfigType.generic).get<string>(Config.firstLine, ""); - this.commentPrefix = workspace.getConfiguration(ConfigType.generic).get<string>(Config.commentPrefix, ""); - this.lastLine = workspace.getConfiguration(ConfigType.generic).get<string>(Config.lastLine, ""); - this.newLineAfterBrief = workspace.getConfiguration(ConfigType.generic).get<boolean>(Config.newLineAfterBrief, true); - this.newLineAfterParams = workspace.getConfiguration(ConfigType.generic).get<boolean>(Config.newLineAfterParams, false); - this.newLineAfterTParams = workspace.getConfiguration(ConfigType.generic).get<boolean>(Config.newLineAfterTParams, false); - this.briefTemplate = workspace.getConfiguration(ConfigType.generic).get<string>(Config.briefTemplate, ""); - this.paramTemplate = workspace.getConfiguration(ConfigType.generic).get<string>(Config.paramTemplate, ""); - this.tparamTemplate = workspace.getConfiguration(ConfigType.generic).get<string>(Config.tparamTemplate, ""); - this.returnTemplate = workspace.getConfiguration(ConfigType.generic).get<string>(Config.returnTemplate, ""); + protected readConfig() { + const getCfg = workspace.getConfiguration; + + this.firstLine = getCfg(ConfigType.generic).get<string>(Config.firstLine, ""); + this.commentPrefix = getCfg(ConfigType.generic).get<string>(Config.commentPrefix, ""); + this.lastLine = getCfg(ConfigType.generic).get<string>(Config.lastLine, ""); + this.newLineAfterBrief = getCfg(ConfigType.generic).get<boolean>(Config.newLineAfterBrief, true); + this.newLineAfterParams = getCfg(ConfigType.generic).get<boolean>(Config.newLineAfterParams, false); + this.newLineAfterTParams = getCfg(ConfigType.generic).get<boolean>(Config.newLineAfterTParams, false); + this.includeTypeAtReturn = getCfg(ConfigType.generic).get<boolean>(Config.includeTypeAtReturn, false); + this.briefTemplate = getCfg(ConfigType.generic).get<string>(Config.briefTemplate, ""); + this.paramTemplate = getCfg(ConfigType.generic).get<string>(Config.paramTemplate, ""); + this.tparamTemplate = getCfg(ConfigType.generic).get<string>(Config.tparamTemplate, ""); + this.returnTemplate = getCfg(ConfigType.generic).get<string>(Config.returnTemplate, ""); } protected getIndentation(): string { @@ -105,11 +116,11 @@ export default class CGen implements IDocGen { protected generateComment(): string { let lines: string[] = []; - + if (this.firstLine.trim().length !== 0) { lines.push(this.firstLine); } - + if (this.briefTemplate.trim().length !== 0) { this.generateBrief(lines); if (this.newLineAfterBrief === true) { @@ -132,11 +143,15 @@ export default class CGen implements IDocGen { } if (this.returnTemplate.trim().length !== 0 && this.retVals.length > 0) { + if (this.includeTypeAtReturn === false) { + this.retVals = this.retVals.map(t => t === "true" || t === "false" ? t : ""); + } + this.generateFromTemplate(lines, this.returnTemplate, this.retVals); } if (this.lastLine.trim().length !== 0) { - lines.push(this.lastLine); + lines.push(this.lastLine); } const comment: string = lines.join("\n" + this.getIndentation()); @@ -148,9 +163,9 @@ export default class CGen implements IDocGen { if (this.firstLine.trim().length !== 0) { line++; } - + character += this.commentPrefix.length + this.briefTemplate.length; - + const move: Selection = new Selection(line, character, line, character); this.activeEditor.selection = move; } diff --git a/src/DocGen/DocGen.ts b/src/DocGen/DocGen.ts index 40ea205..1b5b1e1 100644 --- a/src/DocGen/DocGen.ts +++ b/src/DocGen/DocGen.ts @@ -1,6 +1,5 @@ import { Range } from "vscode"; - export interface IDocGen { /** * @brief Generate documentation string and write it to the active editor |