From 0ebfa5bd12e529d8febe73c85d3bf48c4d4997e8 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sat, 14 Oct 2017 22:29:02 +0200 Subject: -- Added extensive templating the be able to generated different types of doxygen comment. --- src/CodeParser/CodeParserController.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/CodeParser/CodeParserController.ts') diff --git a/src/CodeParser/CodeParserController.ts b/src/CodeParser/CodeParserController.ts index 49d4082..0a80e77 100644 --- a/src/CodeParser/CodeParserController.ts +++ b/src/CodeParser/CodeParserController.ts @@ -1,4 +1,4 @@ -import { Disposable, Position, 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"; @@ -13,7 +13,7 @@ import CppParser from "./CppParser"; */ export default class CodeParserController { private disposable: Disposable; - private indicators: string[] = []; + private triggerSequence: string; /** * Creates an instance of CodeParserController @@ -51,8 +51,7 @@ export default class CodeParserController { ***************************************************************************/ private readConfig() { - this.indicators.pop(); - this.indicators.push(workspace.getConfiguration(ConfigType.generic).get(Config.commentStart, "/**")); + this.triggerSequence = workspace.getConfiguration(ConfigType.generic).get(Config.triggerSequence, "/**"); } private check(activeEditor: TextEditor, event: TextDocumentContentChangeEvent): boolean { @@ -64,7 +63,7 @@ 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; } @@ -72,14 +71,7 @@ export default class CodeParserController { const cont: string = activeLine.text.trim(); let found: boolean = false; - this.indicators.forEach((element: string) => { - if (element === cont) { // Compare the content from the line with the valid indicators - found = true; - return; - } - }); - - return found; + return this.triggerSequence === cont; } private onEvent(activeEditor: TextEditor, event: TextDocumentContentChangeEvent) { @@ -102,6 +94,17 @@ export default class CodeParserController { console.log("No comments can be generated for language: " + lang); return null; } - parser.Parse(activeEditor, event).GenerateDoc(); + + const currentPos: Position = window.activeTextEditor.selection.active; + 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; + // 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); + } + + parser.Parse(activeEditor, event).GenerateDoc(new Range(startReplace, endReplace)); } } -- cgit v1.2.3 From cc0d69edcd362c1abde9d0005c70d8e3692395bc Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 02:26:22 +0200 Subject: -- Fixed tslint issues. -- Added config parameter to add type information to return DoxyGen parameter. --- src/CodeParser/CodeParserController.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/CodeParser/CodeParserController.ts') 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(Config.triggerSequence, "/**"); + this.triggerSequence = workspace + .getConfiguration(ConfigType.generic) + .get(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); -- cgit v1.2.3 From 6c8a34a542e1e79903886368da19613b4ce3b237 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 15 Oct 2017 02:38:58 +0200 Subject: -- tslint fix v3 --- src/CodeParser/CodeParserController.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/CodeParser/CodeParserController.ts') diff --git a/src/CodeParser/CodeParserController.ts b/src/CodeParser/CodeParserController.ts index 054aa38..70941d0 100644 --- a/src/CodeParser/CodeParserController.ts +++ b/src/CodeParser/CodeParserController.ts @@ -1,12 +1,12 @@ -import { - Disposable, - Position, - Range, - TextDocumentContentChangeEvent, - TextEditor, - TextLine, - window, - workspace +import { + Disposable, + Position, + Range, + TextDocumentContentChangeEvent, + TextEditor, + TextLine, + window, + workspace, } from "vscode"; import { Config, ConfigType } from "../Config"; import CodeParser from "./CodeParser"; @@ -107,8 +107,8 @@ export default class CodeParserController { const currentPos: Position = window.activeTextEditor.selection.active; const startReplace: Position = new Position( - currentPos.line, - currentPos.character - this.triggerSequence.length + currentPos.line, + currentPos.character - this.triggerSequence.length, ); let endReplace: Position = new Position(currentPos.line, currentPos.character); -- cgit v1.2.3