-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathproxy.ts
More file actions
executable file
·73 lines (67 loc) · 1.98 KB
/
Copy pathproxy.ts
File metadata and controls
executable file
·73 lines (67 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file hh_client proxy
*/
import * as ps from "child_process";
import * as vscode from "vscode";
import { HackConfig } from "./Config";
import * as remote from "./remote";
import * as hack from "./types/hack";
export async function version(
config: HackConfig,
log: vscode.LogOutputChannel,
): Promise<hack.Version | undefined> {
try {
return JSON.parse(await run(config, log, ["--version"]));
} catch {
return undefined;
}
}
/** Run `hh_client` to start `hh_server` if needed. */
export async function start(
config: HackConfig,
log: vscode.LogOutputChannel,
): Promise<string> {
// Ignore errors to avoid exceeding `maxBuffer` in case of many preexisting errors.
// We only run this command to ensure `hh_server` starts and don't care about the output.
return run(config, log, ["--max-errors", "0"]);
}
async function run(
config: HackConfig,
log: vscode.LogOutputChannel,
extraArgs: string[],
): Promise<string> {
return new Promise((resolve, reject) => {
const workspacePath =
config.remoteEnabled && config.remoteWorkspacePath
? config.remoteWorkspacePath
: config.localWorkspacePath;
const command = remote.getCommand(config, config.clientPath);
const args = remote.getArgs(config, config.clientPath, [
...extraArgs,
"--json",
"--from",
"vscode-hack",
workspacePath,
]);
ps.execFile(
command,
args,
{ maxBuffer: 1024 * 1024 },
(err: any, stdout, stderr) => {
if (!stdout) {
// all hh_client --check output goes to stderr by default
stdout = stderr;
}
const wasError = err !== null && err.code !== 0 && err.code !== 2;
if (wasError) {
const errMsg = `hh_client execution error: ${err}, output: ${stdout}`;
// any hh_client failure other than typecheck errors
log.error(errMsg);
reject(new Error(errMsg));
return;
}
resolve(stdout);
},
);
});
}