diff --git a/editors/vscode/client/tools/lsp_helper.ts b/editors/vscode/client/tools/lsp_helper.ts index ad31ae442715e..a3c7b27041e91 100644 --- a/editors/vscode/client/tools/lsp_helper.ts +++ b/editors/vscode/client/tools/lsp_helper.ts @@ -13,6 +13,7 @@ export function runExecutable(path: string, nodePath?: string, tsgolintPath?: st serverEnv.OXLINT_TSGOLINT_PATH = tsgolintPath; } const isNode = path.endsWith(".js") || path.endsWith(".cjs") || path.endsWith(".mjs"); + const isWindows = process.platform === "win32"; return isNode ? { @@ -23,15 +24,16 @@ export function runExecutable(path: string, nodePath?: string, tsgolintPath?: st }, } : { - command: path, + // On Windows with shell, quote the command path to handle spaces in usernames/paths + command: isWindows ? `"${path}"` : path, args: ["--lsp"], options: { // On Windows we need to run the binary in a shell to be able to execute the shell npm bin script. // Searching for the right `.exe` file inside `node_modules/` is not reliable as it depends on // the package manager used (npm, yarn, pnpm, etc) and the package version. // The npm bin script is a shell script that points to the actual binary. - // Security: We validated the userDefinedBinary in `configService.getUserServerBinPath()`. - shell: process.platform === "win32", + // Security: We validated the user defined binary path in `configService.searchBinaryPath()`. + shell: isWindows, env: serverEnv, }, }; diff --git a/editors/vscode/tests/lsp_helper.spec.ts b/editors/vscode/tests/lsp_helper.spec.ts index f2b3756209975..88d973bdc4030 100644 --- a/editors/vscode/tests/lsp_helper.spec.ts +++ b/editors/vscode/tests/lsp_helper.spec.ts @@ -58,4 +58,12 @@ suite('runExecutable', () => { strictEqual(result.options?.env?.PATH, '/custom/node/path:/usr/bin:/bin'); }); + + test('should set path in quotes on Windows for binary executables', () => { + Object.defineProperty(process, 'platform', { value: 'win32' }); + + const result = runExecutable('C:\\Path With Spaces\\oxc-language-server'); + + strictEqual(result.command, '"C:\\Path With Spaces\\oxc-language-server"'); + }); });