From 68b8b9e43d9a89b342513cfb34f1fe21ac351c38 Mon Sep 17 00:00:00 2001 From: Danny Wilson Date: Mon, 9 Sep 2019 11:08:35 +0400 Subject: [PATCH] Support relative path to python to allow wrapper scripts --- src/extension.ts | 3 ++- src/utils.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index fd14351..373bbee 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -102,12 +102,13 @@ export class Extension { pyArgs.push("--payeeNarration") } this.logger.appendLine(`running ${python3Path} ${pyArgs} to refresh data...`) + let cwd = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri.fsPath : undefined; run_cmd(python3Path, pyArgs, (text: string) => { const errors_completions = text.split('\n', 3) this.provideDiagnostics(errors_completions[0], errors_completions[2]) this.completer.updateData(errors_completions[1]) this.logger.appendLine("Data refreshed.") - }); + }, cwd? {cwd} : undefined, str => this.logger.append(str)); } provideDiagnostics(errors_json: string, flags_json: string) { diff --git a/src/utils.ts b/src/utils.ts index 841d68e..fe0dc51 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,11 @@ -import { spawn } from 'child_process'; +import { spawn, SpawnOptions } from 'child_process'; -export function run_cmd(cmd:string, args:Array, callBack: (stdout: string) => void) { - var child = spawn(cmd, args); +export function run_cmd(cmd: string, args: Array, callBack: (stdout: string) => void, options?: SpawnOptions, logger?: (str: string) => void) { + var child = spawn(cmd, args, options); + if (logger) { + child.on('error', (e) => logger("error: " + e)) + child.stderr.on('data', (e) => logger("stderr: " + e)); + } var resp = ""; child.stdout.on('data', function (buffer) { resp += buffer.toString() }); child.stdout.on('end', function() { callBack (resp) });