fix(lsp): improve Windows server detection

This commit is contained in:
MotorwaySouth9
2026-01-16 08:40:19 +08:00
parent aae089ffcc
commit 2216885d43
2 changed files with 139 additions and 14 deletions
+29 -14
View File
@@ -170,31 +170,46 @@ export function isServerInstalled(command: string[]): boolean {
}
const isWindows = process.platform === "win32"
const ext = isWindows ? ".exe" : ""
let exts = [""]
if (isWindows) {
const pathExt = process.env.PATHEXT || ""
if (pathExt) {
const systemExts = pathExt.split(";").filter(Boolean)
exts = [...new Set([...exts, ...systemExts, ".exe", ".cmd", ".bat", ".ps1"])]
} else {
exts = ["", ".exe", ".cmd", ".bat", ".ps1"]
}
}
const pathEnv = process.env.PATH || ""
let pathEnv = process.env.PATH || ""
if (isWindows && !pathEnv) {
pathEnv = process.env.Path || ""
}
const pathSeparator = isWindows ? ";" : ":"
const paths = pathEnv.split(pathSeparator)
for (const p of paths) {
if (existsSync(join(p, cmd)) || existsSync(join(p, cmd + ext))) {
return true
for (const suffix of exts) {
if (existsSync(join(p, cmd + suffix))) {
return true
}
}
}
const cwd = process.cwd()
const additionalPaths = [
join(cwd, "node_modules", ".bin", cmd),
join(cwd, "node_modules", ".bin", cmd + ext),
join(homedir(), ".config", "opencode", "bin", cmd),
join(homedir(), ".config", "opencode", "bin", cmd + ext),
join(homedir(), ".config", "opencode", "node_modules", ".bin", cmd),
join(homedir(), ".config", "opencode", "node_modules", ".bin", cmd + ext),
const additionalBases = [
join(cwd, "node_modules", ".bin"),
join(homedir(), ".config", "opencode", "bin"),
join(homedir(), ".config", "opencode", "node_modules", ".bin"),
]
for (const p of additionalPaths) {
if (existsSync(p)) {
return true
for (const base of additionalBases) {
for (const suffix of exts) {
if (existsSync(join(base, cmd + suffix))) {
return true
}
}
}