diff options
| author | Christoph Schlosser <christoph@linux.com> | 2018-10-20 15:54:23 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2018-10-20 15:54:23 +0200 |
| commit | 5d64d00fe54d649d0519a3e9f018a1f71cee693b (patch) | |
| tree | b95cf36631668f7050a926cc827324ee26cec23c | |
| parent | df3a5391f49dd3947354963dcf8a23e7ceec2b41 (diff) | |
| download | doxdocgen-5d64d00fe54d649d0519a3e9f018a1f71cee693b.tar.gz | |
Get logical line for python function
| -rw-r--r-- | src/CodeParserController.ts | 7 | ||||
| -rw-r--r-- | src/Lang/Python/PythonParser.ts | 41 |
2 files changed, 44 insertions, 4 deletions
diff --git a/src/CodeParserController.ts b/src/CodeParserController.ts index 4e38f06..a4b4748 100644 --- a/src/CodeParserController.ts +++ b/src/CodeParserController.ts @@ -114,15 +114,19 @@ export default class CodeParserController { } const lang: string = activeEditor.document.languageId; + const currentPos: Position = window.activeTextEditor.selection.active; let parser: CodeParser; + let endPos: number; switch (lang) { case "c": case "cpp": parser = new CppParser(this.cfg); + endPos = currentPos.character - this.cfg.C.triggerSequence.length; break; case "python": parser = new PythonParser(this.cfg); + endPos = currentPos.character - this.cfg.Python.triggerSequence.length; break; default: // tslint:disable-next-line:no-console @@ -130,10 +134,9 @@ export default class CodeParserController { return null; } - const currentPos: Position = window.activeTextEditor.selection.active; const startReplace: Position = new Position( currentPos.line, - currentPos.character - this.cfg.C.triggerSequence.length, + endPos, ); const nextLineText: string = window.activeTextEditor.document.lineAt(startReplace.line + 1).text; diff --git a/src/Lang/Python/PythonParser.ts b/src/Lang/Python/PythonParser.ts index 2d26ed8..74f1bef 100644 --- a/src/Lang/Python/PythonParser.ts +++ b/src/Lang/Python/PythonParser.ts @@ -1,17 +1,54 @@ -import { TextEditor } from "vscode"; +import { Position, TextEditor } from "vscode"; import ICodeParser from "../../Common/ICodeParser"; import { IDocGen } from "../../Common/IDocGen"; import { Config } from "../../Config"; +import { PythonDocGen } from "./PythonDocGen"; export default class CppParser implements ICodeParser { protected readonly cfg: Config; + protected activeSelection: Position; + protected activeEditor: TextEditor; constructor(cfg: Config) { this.cfg = cfg; } public Parse(activeEditor: TextEditor): IDocGen { - throw new Error("Method not implemented."); + this.activeEditor = activeEditor; + this.activeSelection = activeEditor.selection.active; + const params = this.getParams(this.getLogicalLine()); + return new PythonDocGen(); + } + + private getLogicalLine(): string { + let nextLine: Position = new Position(this.activeSelection.line + 1, this.activeSelection.character); + let nextLineTxt: string = this.activeEditor.document.lineAt(nextLine.line).text.trim(); + + let logicalLine = ""; + let linesToGet: number = this.cfg.Generic.linesToGet; + let foundStart = false; + while (linesToGet-- > 0) { // Check for end of expression. + nextLine = new Position(nextLine.line + 1, nextLine.character); + nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim(); + + if (nextLineTxt.startsWith("def")) { + foundStart = true; + } + + if (foundStart) { + logicalLine += nextLineTxt; + } + + if (nextLineTxt.endsWith(":")) { + break; + } + } + + return logicalLine; + } + + private getParams(line: string): string[] { + return []; } } |