From 8f2dd16ab089f6b1ccaa6582adaebf9d1b42f1d4 Mon Sep 17 00:00:00 2001 From: Almenon Date: Mon, 5 Mar 2018 23:49:27 -0800 Subject: [PATCH] #38 allow user to customize python settings --- package.json | 10 ++++++++++ src/PreviewManager.ts | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c55db07..e07248e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,16 @@ "type": "number", "default": 70, "description": "strings over X characters are truncated with an option to expand" + }, + "AREPL.pythonPath": { + "type": "string", + "default": null, + "description": "By default python is used if windows or python3 otherwise. Changing this setting not reccomended" + }, + "AREPL.pythonOptions": { + "type": "array", + "default": ["-u"], + "description": "default -u to see prints in real-time. See https://docs.python.org/3/using/cmdline.html#miscellaneous-options for other options. Changing this setting not reccomended" } } }, diff --git a/src/PreviewManager.ts b/src/PreviewManager.ts index 4a02adc..8522f71 100644 --- a/src/PreviewManager.ts +++ b/src/PreviewManager.ts @@ -16,24 +16,29 @@ export default class PreviewManager { status: vscode.StatusBarItem; constructor(context: vscode.ExtensionContext) { + + const settings = vscode.workspace.getConfiguration('AREPL'); + this.pythonPreviewContentProvider = new HtmlDocumentContentProvider(context); - this.pythonEvaluator = new PythonEvaluator() this.pythonEditor = vscode.window.activeTextEditor.document; this.status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100); this.status.text = "Running python..." this.status.tooltip = "AREPL is currently running your python file. Close the AREPL preview to stop" - - const settings = vscode.workspace.getConfiguration('AREPL'); - + + vscode.workspace.registerTextDocumentContentProvider(HtmlDocumentContentProvider.scheme, this.pythonPreviewContentProvider); - + ///////////////////////////////////////////////////////// // python ///////////////////////////////////////////////////////// - let self:PreviewManager = this; + let pythonPath = settings.get('pythonPath') + let pythonOptions = settings.get('pythonOptions') + + this.pythonEvaluator = new PythonEvaluator(pythonPath, pythonOptions) + let debounce = settings.get('delay'); let restartExtraDebounce = settings.get('restartDelay'); - + this.pythonEvaluator.startPython() this.pythonEvaluator.pyshell.childProcess.on('error', err => { let error:any = err; //typescript complains about type for some reason so defining to any