Skip to content

Commit

Permalink
Merge pull request #27 from vizanto/master
Browse files Browse the repository at this point in the history
Support relative path to python (to allow wrapper scripts)
  • Loading branch information
Lencerf authored Sep 14, 2019
2 parents 0395bcb + 68b8b9e commit 77ee6c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { spawn } from 'child_process';
import { spawn, SpawnOptions } from 'child_process';

export function run_cmd(cmd:string, args:Array<string>, callBack: (stdout: string) => void) {
var child = spawn(cmd, args);
export function run_cmd(cmd: string, args: Array<string>, 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) });
Expand Down

0 comments on commit 77ee6c2

Please sign in to comment.