Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions editors/vscode/client/tools/lsp_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? {
Expand All @@ -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,
},
};
Expand Down
8 changes: 8 additions & 0 deletions editors/vscode/tests/lsp_helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
});
});
Loading