fix: 修复 Windows 上 LSP 服务器启动 ENOENT 错误

Windows 的 spawn() 使用 CreateProcess API,只能直接执行 PE 可执行文件
(.exe/.com),无法解析 npm 全局安装产生的 .cmd 包装脚本。启用 shell 选项
后由 cmd.exe 解析脚本路径,解决 typescript-language-server 等 LSP 服务器
在 Windows 上找不到命令的问题。

Co-Authored-By: Auto <noreply@anthropic.com>
This commit is contained in:
Askhz 2026-05-19 09:32:07 +08:00
parent 2ae463a8fe
commit 8dfd1ddc0b

View File

@ -1,4 +1,5 @@
import { type ChildProcess, spawn } from 'child_process' import { type ChildProcess, spawn } from 'child_process'
import { platform } from 'os'
import { import {
createMessageConnection, createMessageConnection,
type MessageConnection, type MessageConnection,
@ -101,6 +102,11 @@ export function createLSPClient(
cwd: options?.cwd, cwd: options?.cwd,
// Prevent visible console window on Windows (no-op on other platforms) // Prevent visible console window on Windows (no-op on other platforms)
windowsHide: true, windowsHide: true,
// On Windows, npm-installed packages produce .cmd wrapper scripts.
// spawn() without shell uses CreateProcess, which only handles PE
// executables (.exe/.com) — .cmd/.bat files cause ENOENT. Enabling
// the shell lets cmd.exe resolve the wrapper.
shell: platform() === 'win32',
}) })
if (!process.stdout || !process.stdin) { if (!process.stdout || !process.stdin) {