Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 0d1c6e0

Browse files
authored
fix(win32): Missing LSP can now unzip on windows (anomalyco#5594)
1 parent 002db3a commit 0d1c6e0

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

packages/opencode/src/lsp/server.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import fs from "fs/promises"
99
import { Filesystem } from "../util/filesystem"
1010
import { Instance } from "../project/instance"
1111
import { Flag } from "../flag/flag"
12+
import { Archive } from "../util/archive"
1213

1314
export namespace LSPServer {
1415
const log = Log.create({ service: "lsp.server" })
@@ -176,7 +177,7 @@ export namespace LSPServer {
176177
const zipPath = path.join(Global.Path.bin, "vscode-eslint.zip")
177178
await Bun.file(zipPath).write(response)
178179

179-
await $`unzip -o -q ${zipPath}`.quiet().cwd(Global.Path.bin).nothrow()
180+
await Archive.extractZip(zipPath, Global.Path.bin)
180181
await fs.rm(zipPath, { force: true })
181182

182183
const extractedPath = path.join(Global.Path.bin, "vscode-eslint-main")
@@ -438,7 +439,7 @@ export namespace LSPServer {
438439
const zipPath = path.join(Global.Path.bin, "elixir-ls.zip")
439440
await Bun.file(zipPath).write(response)
440441

441-
await $`unzip -o -q ${zipPath}`.quiet().cwd(Global.Path.bin).nothrow()
442+
await Archive.extractZip(zipPath, Global.Path.bin)
442443

443444
await fs.rm(zipPath, {
444445
force: true,
@@ -541,7 +542,7 @@ export namespace LSPServer {
541542
await Bun.file(tempPath).write(downloadResponse)
542543

543544
if (ext === "zip") {
544-
await $`unzip -o -q ${tempPath}`.quiet().cwd(Global.Path.bin).nothrow()
545+
await Archive.extractZip(tempPath, Global.Path.bin)
545546
} else {
546547
await $`tar -xf ${tempPath}`.cwd(Global.Path.bin).nothrow()
547548
}
@@ -840,7 +841,7 @@ export namespace LSPServer {
840841
}
841842

842843
if (zip) {
843-
await $`unzip -o -q ${archive}`.quiet().cwd(Global.Path.bin).nothrow()
844+
await Archive.extractZip(archive, Global.Path.bin)
844845
}
845846
if (tar) {
846847
await $`tar -xf ${archive}`.cwd(Global.Path.bin).nothrow()
@@ -1188,14 +1189,21 @@ export namespace LSPServer {
11881189
await fs.mkdir(installDir, { recursive: true })
11891190

11901191
if (ext === "zip") {
1191-
const ok = await $`unzip -o -q ${tempPath} -d ${installDir}`.quiet().catch((error) => {
1192-
log.error("Failed to extract lua-language-server archive", { error })
1193-
})
1192+
const ok = await Archive.extractZip(tempPath, installDir)
1193+
.then(() => true)
1194+
.catch((error) => {
1195+
log.error("Failed to extract lua-language-server archive", { error })
1196+
return false
1197+
})
11941198
if (!ok) return
11951199
} else {
1196-
const ok = await $`tar -xzf ${tempPath} -C ${installDir}`.quiet().catch((error) => {
1197-
log.error("Failed to extract lua-language-server archive", { error })
1198-
})
1200+
const ok = await $`tar -xzf ${tempPath} -C ${installDir}`
1201+
.quiet()
1202+
.then(() => true)
1203+
.catch((error) => {
1204+
log.error("Failed to extract lua-language-server archive", { error })
1205+
return false
1206+
})
11991207
if (!ok) return
12001208
}
12011209

@@ -1396,7 +1404,7 @@ export namespace LSPServer {
13961404
const tempPath = path.join(Global.Path.bin, assetName)
13971405
await Bun.file(tempPath).write(downloadResponse)
13981406

1399-
await $`unzip -o -q ${tempPath}`.cwd(Global.Path.bin).nothrow()
1407+
await Archive.extractZip(tempPath, Global.Path.bin)
14001408
await fs.rm(tempPath, { force: true })
14011409

14021410
bin = path.join(Global.Path.bin, "terraform-ls" + (platform === "win32" ? ".exe" : ""))
@@ -1481,7 +1489,7 @@ export namespace LSPServer {
14811489
await Bun.file(tempPath).write(downloadResponse)
14821490

14831491
if (ext === "zip") {
1484-
await $`unzip -o -q ${tempPath}`.cwd(Global.Path.bin).nothrow()
1492+
await Archive.extractZip(tempPath, Global.Path.bin)
14851493
}
14861494
if (ext === "tar.gz") {
14871495
await $`tar -xzf ${tempPath}`.cwd(Global.Path.bin).nothrow()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { $ } from "bun"
2+
import path from "path"
3+
4+
export namespace Archive {
5+
export async function extractZip(zipPath: string, destDir: string) {
6+
if (process.platform === "win32") {
7+
const winZipPath = path.resolve(zipPath)
8+
const winDestDir = path.resolve(destDir)
9+
// $global:ProgressPreference suppresses PowerShell's blue progress bar popup
10+
const cmd = `$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive -Path '${winZipPath}' -DestinationPath '${winDestDir}' -Force`
11+
await $`powershell -NoProfile -NonInteractive -Command ${cmd}`.quiet()
12+
} else {
13+
await $`unzip -o -q ${zipPath} -d ${destDir}`.quiet()
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)