fix(lsp): use HashiCorp releases API for installing terraform-ls (#14200)

This commit is contained in:
Eduardo Bellido Bellido
2026-02-18 23:11:57 +01:00
committed by GitHub
parent d366a1430f
commit 87c16374aa

View File

@@ -1654,22 +1654,17 @@ export namespace LSPServer {
if (!bin) { if (!bin) {
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
log.info("downloading terraform-ls from GitHub releases") log.info("downloading terraform-ls from HashiCorp releases")
const releaseResponse = await fetch("https://api.github.com/repos/hashicorp/terraform-ls/releases/latest") const releaseResponse = await fetch("https://api.releases.hashicorp.com/v1/releases/terraform-ls/latest")
if (!releaseResponse.ok) { if (!releaseResponse.ok) {
log.error("Failed to fetch terraform-ls release info") log.error("Failed to fetch terraform-ls release info")
return return
} }
const release = (await releaseResponse.json()) as { const release = (await releaseResponse.json()) as {
tag_name?: string version?: string
assets?: { name?: string; browser_download_url?: string }[] builds?: { arch?: string; os?: string; url?: string }[]
}
const version = release.tag_name?.replace("v", "")
if (!version) {
log.error("terraform-ls release did not include a version tag")
return
} }
const platform = process.platform const platform = process.platform
@@ -1678,22 +1673,20 @@ export namespace LSPServer {
const tfArch = arch === "arm64" ? "arm64" : "amd64" const tfArch = arch === "arm64" ? "arm64" : "amd64"
const tfPlatform = platform === "win32" ? "windows" : platform const tfPlatform = platform === "win32" ? "windows" : platform
const assetName = `terraform-ls_${version}_${tfPlatform}_${tfArch}.zip` const builds = release.builds ?? []
const build = builds.find((b) => b.arch === tfArch && b.os === tfPlatform)
const assets = release.assets ?? [] if (!build?.url) {
const asset = assets.find((a) => a.name === assetName) log.error(`Could not find build for ${tfPlatform}/${tfArch} terraform-ls release version ${release.version}`)
if (!asset?.browser_download_url) {
log.error(`Could not find asset ${assetName} in terraform-ls release`)
return return
} }
const downloadResponse = await fetch(asset.browser_download_url) const downloadResponse = await fetch(build.url)
if (!downloadResponse.ok) { if (!downloadResponse.ok) {
log.error("Failed to download terraform-ls") log.error("Failed to download terraform-ls")
return return
} }
const tempPath = path.join(Global.Path.bin, assetName) const tempPath = path.join(Global.Path.bin, "terraform-ls.zip")
if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body) if (downloadResponse.body) await Filesystem.writeStream(tempPath, downloadResponse.body)
const ok = await Archive.extractZip(tempPath, Global.Path.bin) const ok = await Archive.extractZip(tempPath, Global.Path.bin)