From 97fc4fc196b5e8e255b8bd73538e8b668fac9083 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Sat, 6 Feb 2021 05:08:29 -0800 Subject: [PATCH 1/2] execSync -> execFileSync for RescriptEditorSupport binary invocation Part of #81 --- server/src/RescriptEditorSupport.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/src/RescriptEditorSupport.ts b/server/src/RescriptEditorSupport.ts index cdc559e8f..e81abe457 100644 --- a/server/src/RescriptEditorSupport.ts +++ b/server/src/RescriptEditorSupport.ts @@ -2,7 +2,7 @@ import { fileURLToPath } from "url"; import { RequestMessage } from "vscode-languageserver"; import * as utils from "./utils"; import * as path from "path"; -import { execSync } from "child_process"; +import { execFileSync } from "child_process"; import fs from "fs"; let binaryPath = path.join( @@ -20,7 +20,7 @@ let findExecutable = (uri: string) => { return null; } else { return { - binaryPathQuoted: '"' + binaryPath + '"', // path could have white space + binaryPath: binaryPath, filePathQuoted: '"' + filePath + '"', cwd: projectRootPath, }; @@ -38,8 +38,6 @@ export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null { } let command = - executable.binaryPathQuoted + - " dump " + executable.filePathQuoted + ":" + msg.params.position.line + @@ -47,7 +45,9 @@ export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null { msg.params.position.character; try { - let stdout = execSync(command, { cwd: executable.cwd }); + let stdout = execFileSync(executable.binaryPath, ["dump", command], { + cwd: executable.cwd, + }); let parsed = JSON.parse(stdout.toString()); if (parsed && parsed[0]) { return parsed[0]; @@ -73,18 +73,18 @@ export function runCompletionCommand( fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let command = - executable.binaryPathQuoted + - " complete " + executable.filePathQuoted + ":" + msg.params.position.line + ":" + - msg.params.position.character + - " " + - tmpname; + msg.params.position.character; try { - let stdout = execSync(command, { cwd: executable.cwd }); + let stdout = execFileSync( + executable.binaryPath, + ["complete", command, tmpname], + { cwd: executable.cwd } + ); let parsed = JSON.parse(stdout.toString()); if (parsed && parsed[0]) { return parsed; From f36c47d9f71a901a422b23c1e3833effdf0788d9 Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Sat, 6 Feb 2021 05:47:38 -0800 Subject: [PATCH 2/2] No need to quote any path in RescriptEditorSupport anymore --- server/src/RescriptEditorSupport.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/RescriptEditorSupport.ts b/server/src/RescriptEditorSupport.ts index e81abe457..bf5d2d654 100644 --- a/server/src/RescriptEditorSupport.ts +++ b/server/src/RescriptEditorSupport.ts @@ -21,7 +21,7 @@ let findExecutable = (uri: string) => { } else { return { binaryPath: binaryPath, - filePathQuoted: '"' + filePath + '"', + filePath: filePath, cwd: projectRootPath, }; } @@ -38,7 +38,7 @@ export function runDumpCommand(msg: RequestMessage): dumpCommandResult | null { } let command = - executable.filePathQuoted + + executable.filePath + ":" + msg.params.position.line + ":" + @@ -73,7 +73,7 @@ export function runCompletionCommand( fs.writeFileSync(tmpname, code, { encoding: "utf-8" }); let command = - executable.filePathQuoted + + executable.filePath + ":" + msg.params.position.line + ":" +