From 8dfd1ddc0b3ee44a720131dd78d3aa4fa187c107 Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Tue, 19 May 2026 09:32:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Windows=20=E4=B8=8A?= =?UTF-8?q?=20LSP=20=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=90=AF=E5=8A=A8=20ENOENT?= =?UTF-8?q?=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows 的 spawn() 使用 CreateProcess API,只能直接执行 PE 可执行文件 (.exe/.com),无法解析 npm 全局安装产生的 .cmd 包装脚本。启用 shell 选项 后由 cmd.exe 解析脚本路径,解决 typescript-language-server 等 LSP 服务器 在 Windows 上找不到命令的问题。 Co-Authored-By: Auto --- src/services/lsp/LSPClient.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/services/lsp/LSPClient.ts b/src/services/lsp/LSPClient.ts index 5ac8509cb..3a6177a42 100644 --- a/src/services/lsp/LSPClient.ts +++ b/src/services/lsp/LSPClient.ts @@ -1,4 +1,5 @@ import { type ChildProcess, spawn } from 'child_process' +import { platform } from 'os' import { createMessageConnection, type MessageConnection, @@ -101,6 +102,11 @@ export function createLSPClient( cwd: options?.cwd, // Prevent visible console window on Windows (no-op on other platforms) 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) {