fix(lsp): improve Windows server detection
This commit is contained in:
+29
-14
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user