diff options
| author | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2017-10-15 20:12:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-15 20:12:01 +0200 |
| commit | c7ebe707bbfbe52c75646a111600986d6c584d03 (patch) | |
| tree | f5435eda43b5d9bd22348f4400028c07b4a446c8 /src/CodeParser/CodeParserController.ts | |
| parent | 140229888a0e4a120c11ecaae81132d07cc69e5b (diff) | |
| parent | 32baa67d95609fc2b0f20c582fe152eeee98ff35 (diff) | |
| download | doxdocgen-c7ebe707bbfbe52c75646a111600986d6c584d03.tar.gz | |
Merge pull request #16 from rowanG077/master
-- Added extensive templating the be able to generated different type…
Diffstat (limited to 'src/CodeParser/CodeParserController.ts')
| -rw-r--r-- | src/CodeParser/CodeParserController.ts | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/CodeParser/CodeParserController.ts b/src/CodeParser/CodeParserController.ts index 49d4082..70941d0 100644 --- a/src/CodeParser/CodeParserController.ts +++ b/src/CodeParser/CodeParserController.ts @@ -1,4 +1,13 @@ -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 +22,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 +60,9 @@ export default class CodeParserController { ***************************************************************************/ private readConfig() { - this.indicators.pop(); - this.indicators.push(workspace.getConfiguration(ConfigType.generic).get<string>(Config.commentStart, "/**")); + this.triggerSequence = workspace + .getConfiguration(ConfigType.generic) + .get<string>(Config.triggerSequence, "/**"); } private check(activeEditor: TextEditor, event: TextDocumentContentChangeEvent): boolean { @@ -70,16 +80,8 @@ 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 +104,20 @@ 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)); } } |