diff options
| author | William Boman <william@redwill.se> | 2022-05-01 22:16:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-01 22:16:51 +0200 |
| commit | 5b4b790f40794d9579b6330aa8cccadf5e0e50ed (patch) | |
| tree | 2e498d7d2cbc87f9f83435019fef787810af49db /lua/nvim-lsp-installer | |
| parent | add hoon_ls (#570) (diff) | |
| download | mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.tar mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.tar.gz mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.tar.bz2 mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.tar.lz mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.tar.xz mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.tar.zst mason-5b4b790f40794d9579b6330aa8cccadf5e0e50ed.zip | |
fix(hls): download archive from downloads.haskell.org (#651)
Diffstat (limited to 'lua/nvim-lsp-installer')
| -rw-r--r-- | lua/nvim-lsp-installer/core/managers/std/init.lua | 27 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/receipt.lua | 10 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/servers/hls/init.lua | 70 |
3 files changed, 89 insertions, 18 deletions
diff --git a/lua/nvim-lsp-installer/core/managers/std/init.lua b/lua/nvim-lsp-installer/core/managers/std/init.lua index 05495573..ded0361a 100644 --- a/lua/nvim-lsp-installer/core/managers/std/init.lua +++ b/lua/nvim-lsp-installer/core/managers/std/init.lua @@ -120,19 +120,25 @@ end ---@async ---@param file string -function M.untarxz(file) +---@param opts {strip_components:integer} +function M.untarxz(file, opts) + opts = opts or {} local ctx = installer.context() platform.when { unix = function() - M.untar(file) + M.untar(file, opts) end, win = function() Result.run_catching(function() win_extract(file) -- unpack .tar.xz to .tar local uncompressed_tar = file:gsub(".xz$", "") - M.untar(uncompressed_tar) + M.untar(uncompressed_tar, opts) end):recover(function() - ctx.spawn.arc { "unarchive", file } + ctx.spawn.arc { + "unarchive", + opts.strip_components and { "--strip-components", opts.strip_components } or vim.NIL, + file, + } pcall(function() ctx.fs:unlink(file) end) @@ -165,4 +171,17 @@ function M.chmod(flags, files) end end +---@async +---Wrapper around vim.ui.select. +---@param items table +---@params opts +function M.select(items, opts) + assert(not platform.is_headless, "Tried to prompt for user input while in headless mode.") + if vim.in_fast_event() then + a.scheduler() + end + local async_select = a.promisify(vim.ui.select) + return async_select(items, opts) +end + return M diff --git a/lua/nvim-lsp-installer/core/receipt.lua b/lua/nvim-lsp-installer/core/receipt.lua index 4517256a..b2300774 100644 --- a/lua/nvim-lsp-installer/core/receipt.lua +++ b/lua/nvim-lsp-installer/core/receipt.lua @@ -126,6 +126,16 @@ InstallReceiptBuilder.opam = package_source "opam" InstallReceiptBuilder.unmanaged = { type = "unmanaged" } +---@param repo string +---@param release string +function InstallReceiptBuilder.github_release(repo, release) + return { + type = "github_release", + repo = repo, + release = release, + } +end + ---@param dependency string function InstallReceiptBuilder.system(dependency) return { type = "system", dependency = dependency } diff --git a/lua/nvim-lsp-installer/servers/hls/init.lua b/lua/nvim-lsp-installer/servers/hls/init.lua index a154a4f2..8c684e01 100644 --- a/lua/nvim-lsp-installer/servers/hls/init.lua +++ b/lua/nvim-lsp-installer/servers/hls/init.lua @@ -2,7 +2,9 @@ local server = require "nvim-lsp-installer.server" local platform = require "nvim-lsp-installer.platform" local process = require "nvim-lsp-installer.process" local Data = require "nvim-lsp-installer.data" -local github = require "nvim-lsp-installer.core.managers.github" +local std = require "nvim-lsp-installer.core.managers.std" +local github_client = require "nvim-lsp-installer.core.managers.github.client" +local path = require "nvim-lsp-installer.path" local coalesce, when = Data.coalesce, Data.when @@ -15,24 +17,64 @@ return function(name, root_dir) async = true, ---@param ctx InstallContext installer = function(ctx) - github.untargz_release_file({ - repo = "haskell/haskell-language-server", - asset_file = function(version) - local target = coalesce( - when(platform.is_mac, "haskell-language-server-macOS-%s.tar.gz"), - when(platform.is_linux, "haskell-language-server-Linux-%s.tar.gz"), - when(platform.is_win, "haskell-language-server-Windows-%s.tar.gz") + local repo = "haskell/haskell-language-server" + local release = ctx.requested_version:or_else_get(function() + return github_client.fetch_latest_release(repo) + :map( + ---@param release GitHubRelease + function(release) + return release.tag_name + end ) - return target and target:format(version) - end, - }).with_receipt() - if platform.is_unix then - ctx.spawn.sh { "-c", [[ chmod +x haskell* ]] } + :get_or_throw() + end) + + local asset_file = coalesce( + when(platform.is.mac_arm64, "haskell-language-server-%s-aarch64-darwin.tar.xz"), + when(platform.is.mac_x64, "haskell-language-server-%s-x86_64-darwin.tar.xz"), + when(platform.is.win_x64, "haskell-language-server-%s-x86_64-unknown-mingw32.zip") + ) + + if not asset_file and platform.is_linux then + asset_file = std.select({ + "haskell-language-server-%s-aarch64-linux-deb10.tar.xz", + "haskell-language-server-%s-x86_64-linux-centos7.tar.xz", + "haskell-language-server-%s-x86_64-linux-deb10.tar.xz", + "haskell-language-server-%s-x86_64-linux-deb9.tar.xz", + "haskell-language-server-%s-x86_64-linux-fedora27.tar.xz", + }, { + prompt = "[hls] Unable to determine which distribution to download, please select one.", + format_item = function(item) + return item:format(release) + end, + }) end + + assert(asset_file, "Couldn't determine which archive to download.") + + local download_url = ("https://downloads.haskell.org/~hls/haskell-language-server-%s/%s"):format( + release, + asset_file:format(release) + ) + + platform.when { + unix = function() + std.download_file(download_url, "haskell-language-server.tar.xz") + std.untarxz("haskell-language-server.tar.xz", { strip_components = 1 }) + end, + win = function() + std.download_file(download_url, "haskell-language-server.zip") + std.unzip("haskell-language-server.zip", ".") + end, + } + + ctx.receipt:with_primary_source(ctx.receipt.github_release(repo, release)) end, default_options = { cmd_env = { - PATH = process.extend_path { root_dir }, + PATH = process.extend_path { + platform.is_win and root_dir or path.concat { root_dir, "bin" }, + }, }, }, } |
