aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-11-18 16:07:53 +0100
committerGitHub <noreply@github.com>2022-11-18 16:07:53 +0100
commit36231e6dad8d31ef024aeda6437c025ba3b87e66 (patch)
tree454fa854ee77e146d3a27e247329e65565a852e5 /lua
parentchore: update generated code (#673) (diff)
downloadmason-36231e6dad8d31ef024aeda6437c025ba3b87e66.tar
mason-36231e6dad8d31ef024aeda6437c025ba3b87e66.tar.gz
mason-36231e6dad8d31ef024aeda6437c025ba3b87e66.tar.bz2
mason-36231e6dad8d31ef024aeda6437c025ba3b87e66.tar.lz
mason-36231e6dad8d31ef024aeda6437c025ba3b87e66.tar.xz
mason-36231e6dad8d31ef024aeda6437c025ba3b87e66.tar.zst
mason-36231e6dad8d31ef024aeda6437c025ba3b87e66.zip
fix(dhall-lsp): github release doesn't always include lsp server asset (#675)
This is a doozy
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-registry/dhall-lsp/init.lua78
1 files changed, 44 insertions, 34 deletions
diff --git a/lua/mason-registry/dhall-lsp/init.lua b/lua/mason-registry/dhall-lsp/init.lua
index 5ef3994b..6e69d68d 100644
--- a/lua/mason-registry/dhall-lsp/init.lua
+++ b/lua/mason-registry/dhall-lsp/init.lua
@@ -5,6 +5,7 @@ local _ = require "mason-core.functional"
local std = require "mason-core.managers.std"
local github_client = require "mason-core.managers.github.client"
local Optional = require "mason-core.optional"
+local Result = require "mason-core.result"
return Pkg.new {
name = "dhall-lsp",
@@ -15,47 +16,56 @@ return Pkg.new {
---@async
---@param ctx InstallContext
install = function(ctx)
+ local asset_name_pattern = assert(
+ _.coalesce(
+ _.when(platform.is.mac, "dhall%-lsp%-server%-.+%-x86_64%-[mM]acos.tar.bz2"),
+ _.when(platform.is.linux_x64, "dhall%-lsp%-server%-.+%-x86_64%-[lL]inux.tar.bz2"),
+ _.when(platform.is.win_x64, "dhall%-lsp%-server%-.+%-x86_64%-[wW]indows.zip")
+ ),
+ "Current platform is not supported."
+ )
+ local find_lsp_server_asset =
+ _.compose(_.find_first(_.prop_satisfies(_.matches(asset_name_pattern), "name")), _.prop "assets")
+
local repo = "dhall-lang/dhall-haskell"
---@type GitHubRelease
- local gh_release = ctx.requested_version
+ local release = ctx.requested_version
:map(function(version)
- return github_client.fetch_release(repo, version)
+ return github_client.fetch_release(repo, version):and_then(
+ _.if_else(
+ find_lsp_server_asset,
+ Result.success,
+ _.always(Result.failure "Unable to find asset file in GitHub release.")
+ )
+ )
end)
:or_else_get(function()
- return github_client.fetch_latest_release(repo)
+ return github_client.fetch_releases(repo):and_then(function(releases)
+ return Optional.of_nilable(_.find_first(find_lsp_server_asset, releases))
+ :ok_or "Unable to find GitHub release."
+ end)
end)
- :get_or_throw()
+ :get_or_throw "Unable to find GitHub release."
- local asset_name_pattern = assert(
- _.coalesce(
- _.when(platform.is.mac, "dhall%-lsp%-server%-.+%-x86_64%-[mM]acos.tar.bz2"),
- _.when(platform.is.linux_x64, "dhall%-lsp%-server%-.+%-x86_64%-[lL]inux.tar.bz2"),
- _.when(platform.is.win_x64, "dhall%-lsp%-server%-.+%-x86_64%-[wW]indows.zip")
- )
- )
- local dhall_lsp_server_asset =
- _.find_first(_.prop_satisfies(_.matches(asset_name_pattern), "name"), gh_release.assets)
- Optional.of_nilable(dhall_lsp_server_asset)
- :if_present(
- ---@param asset GitHubReleaseAsset
- function(asset)
- if platform.is.win then
- std.download_file(asset.browser_download_url, "dhall-lsp-server.zip")
- std.unzip("dhall-lsp-server.zip", ".")
- else
- std.download_file(asset.browser_download_url, "dhall-lsp-server.tar.bz2")
- std.untar "dhall-lsp-server.tar.bz2"
- std.chmod("+x", { path.concat { "bin", "dhall-lsp-server" } })
- end
- ctx.receipt:with_primary_source {
- type = "github_release_file",
- repo = repo,
- file = asset.browser_download_url,
- release = gh_release.tag_name,
- }
- end
- )
- :or_else_throw "Unable to find the dhall-lsp-server release asset in the GitHub release."
+ local asset = find_lsp_server_asset(release)
+
+ platform.when {
+ win = function()
+ std.download_file(asset.browser_download_url, "dhall-lsp-server.zip")
+ std.unzip("dhall-lsp-server.zip", ".")
+ end,
+ unix = function()
+ std.download_file(asset.browser_download_url, "dhall-lsp-server.tar.bz2")
+ std.untar "dhall-lsp-server.tar.bz2"
+ std.chmod("+x", { path.concat { "bin", "dhall-lsp-server" } })
+ end,
+ }
+ ctx.receipt:with_primary_source {
+ type = "github_release_file",
+ repo = repo,
+ file = asset.browser_download_url,
+ release = release.tag_name,
+ }
ctx:link_bin(
"dhall-lsp-server",