Skip to content

Commit 06518b6

Browse files
committed
execSync -> execFileSync for RescriptEditorSupport binary invocation
Part of #81
1 parent 04fa844 commit 06518b6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

server/src/RescriptEditorSupport.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fileURLToPath } from "url";
22
import { RequestMessage } from "vscode-languageserver";
33
import * as utils from "./utils";
44
import * as path from "path";
5-
import { execSync } from "child_process";
5+
import { execFileSync } from "child_process";
66
import fs from "fs";
77

88
let binaryPath = path.join(
@@ -20,7 +20,7 @@ let findExecutable = (uri: string) => {
2020
return null;
2121
} else {
2222
return {
23-
binaryPathQuoted: '"' + binaryPath + '"', // path could have white space
23+
binaryPath: binaryPath,
2424
filePathQuoted: '"' + filePath + '"',
2525
cwd: projectRootPath,
2626
};
@@ -38,16 +38,18 @@ export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null {
3838
}
3939

4040
let command =
41-
executable.binaryPathQuoted +
42-
" dump " +
4341
executable.filePathQuoted +
4442
":" +
4543
msg.params.position.line +
4644
":" +
4745
msg.params.position.character;
4846

4947
try {
50-
let stdout = execSync(command, { cwd: executable.cwd });
48+
let stdout = execFileSync(
49+
executable.binaryPath,
50+
["dump", command],
51+
{ cwd: executable.cwd }
52+
);
5153
let parsed = JSON.parse(stdout.toString());
5254
if (parsed && parsed[0]) {
5355
return parsed[0];
@@ -73,8 +75,6 @@ export function runCompletionCommand(
7375
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
7476

7577
let command =
76-
executable.binaryPathQuoted +
77-
" complete " +
7878
executable.filePathQuoted +
7979
":" +
8080
msg.params.position.line +
@@ -84,7 +84,10 @@ export function runCompletionCommand(
8484
tmpname;
8585

8686
try {
87-
let stdout = execSync(command, { cwd: executable.cwd });
87+
let stdout = execFileSync(
88+
executable.binaryPath,
89+
["complete", command],
90+
{ cwd: executable.cwd });
8891
let parsed = JSON.parse(stdout.toString());
8992
if (parsed && parsed[0]) {
9093
return parsed;

0 commit comments

Comments
 (0)