aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-04-21 12:09:59 +0200
committerGitHub <noreply@github.com>2022-04-21 12:09:59 +0200
commitb68fcc6bb2c770495ff8e2508c06dfdd49abcc80 (patch)
treedf7c71efb59958deb21a18eeccf3e3c43c4cd704 /lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua
parentrun autogen_metadata.lua (diff)
downloadmason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.gz
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.bz2
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.lz
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.xz
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.zst
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.zip
chore: refactor remaining installers to async impl (#616)
Diffstat (limited to 'lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua')
-rw-r--r--lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua79
1 files changed, 52 insertions, 27 deletions
diff --git a/lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua b/lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua
index 407f9d5a..27604f0c 100644
--- a/lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua
+++ b/lua/nvim-lsp-installer/servers/dhall_lsp_server/init.lua
@@ -2,17 +2,12 @@ local server = require "nvim-lsp-installer.server"
local path = require "nvim-lsp-installer.path"
local process = require "nvim-lsp-installer.process"
local platform = require "nvim-lsp-installer.platform"
-local std = require "nvim-lsp-installer.installers.std"
-local context = require "nvim-lsp-installer.installers.context"
local Data = require "nvim-lsp-installer.data"
+local std = require "nvim-lsp-installer.core.managers.std"
+local github_client = require "nvim-lsp-installer.core.managers.github.client"
+local Optional = require "nvim-lsp-installer.core.optional"
-local coalesce, when = Data.coalesce, Data.when
-
-local target = coalesce(
- when(platform.is_mac, "dhall-lsp-server-1.0.18-x86_64-macos.tar.bz2"),
- when(platform.is_linux, "dhall-lsp-server-1.0.18-x86_64-linux.tar.bz2"),
- when(platform.is_win, "dhall-lsp-server-1.0.18-x86_64-windows.zip")
-)
+local coalesce, when, list_find_first = Data.coalesce, Data.when, Data.list_find_first
return function(name, root_dir)
return server.Server:new {
@@ -20,26 +15,56 @@ return function(name, root_dir)
root_dir = root_dir,
homepage = "https://dhall-lang.org/",
languages = { "dhall" },
- installer = {
- context.set(function(ctx)
- ctx.requested_server_version = Data.coalesce(
- ctx.requested_server_version,
- "1.41.1" -- https://github.com/williamboman/nvim-lsp-installer/pull/512#discussion_r817062340
+ async = true,
+ ---@param ctx InstallContext
+ installer = function(ctx)
+ local repo = "dhall-lang/dhall-haskell"
+ ---@type GitHubRelease
+ local gh_release = ctx.requested_version
+ :map(function(version)
+ return github_client.fetch_release(repo, version)
+ end)
+ :or_else_get(function()
+ return github_client.fetch_latest_release(repo)
+ end)
+ :get_or_throw()
+
+ local asset_name_pattern = assert(
+ coalesce(
+ when(platform.is_mac, "dhall%-lsp%-server%-.+%-x86_64%-macos.tar.bz2"),
+ when(platform.is_linux, "dhall%-lsp%-server%-.+%-x86_64%-linux.tar.bz2"),
+ when(platform.is_win, "dhall%-lsp%-server%-.+%-x86_64%-windows.zip")
)
- end),
- context.use_github_release_file("dhall-lang/dhall-haskell", target),
- context.capture(function(ctx)
- if platform.is_win then
- return std.unzip_remote(ctx.github_release_file)
- else
- return std.untargz_remote(ctx.github_release_file)
+ )
+ local dhall_lsp_server_asset = list_find_first(
+ gh_release.assets,
+ ---@param asset GitHubReleaseAsset
+ function(asset)
+ return asset.name:match(asset_name_pattern)
end
- end),
- std.chmod("+x", { path.concat { "bin", "dhall-lsp-server" } }),
- context.receipt(function(receipt, ctx)
- receipt:with_primary_source(receipt.github_release_file(ctx))
- end),
- },
+ )
+ 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."
+ end,
default_options = {
cmd_env = {
PATH = process.extend_path { path.concat { root_dir, "bin" } },