diff options
Diffstat (limited to 'lua/nvim-lsp-installer')
4 files changed, 55 insertions, 54 deletions
diff --git a/lua/nvim-lsp-installer/core/managers/git/init.lua b/lua/nvim-lsp-installer/core/managers/git/init.lua index 6efa10b9..559703c9 100644 --- a/lua/nvim-lsp-installer/core/managers/git/init.lua +++ b/lua/nvim-lsp-installer/core/managers/git/init.lua @@ -1,6 +1,7 @@ local spawn = require "nvim-lsp-installer.core.spawn" local Result = require "nvim-lsp-installer.core.result" local installer = require "nvim-lsp-installer.core.installer" +local _ = require "nvim-lsp-installer.core.functional" local M = {} @@ -13,7 +14,7 @@ local function with_receipt(repo) end ---@async ----@param opts {[1]: string, recursive: boolean} @The first item in the table is the repository to clone. +---@param opts {[1]: string, recursive: boolean, version: Optional|nil} @The first item in the table is the repository to clone. function M.clone(opts) local ctx = installer.context() local repo = assert(opts[1], "No git URL provided.") @@ -25,7 +26,7 @@ function M.clone(opts) repo, ".", } - ctx.requested_version:if_present(function(version) + _.coalesce(opts.version, ctx.requested_version):if_present(function(version) ctx.spawn.git { "fetch", "--depth", "1", "origin", version } ctx.spawn.git { "checkout", "FETCH_HEAD" } end) diff --git a/lua/nvim-lsp-installer/core/managers/github/init.lua b/lua/nvim-lsp-installer/core/managers/github/init.lua index 58856b66..b3721705 100644 --- a/lua/nvim-lsp-installer/core/managers/github/init.lua +++ b/lua/nvim-lsp-installer/core/managers/github/init.lua @@ -3,6 +3,7 @@ local std = require "nvim-lsp-installer.core.managers.std" local client = require "nvim-lsp-installer.core.managers.github.client" local platform = require "nvim-lsp-installer.core.platform" local Result = require "nvim-lsp-installer.core.result" +local _ = require "nvim-lsp-installer.core.functional" local M = {} @@ -21,15 +22,26 @@ local function with_release_file_receipt(repo, asset_file, release) end end +---@param repo string +---@param tag string +local function with_tag_receipt(repo, tag) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source { + type = "github_tag", + repo = repo, + tag = tag, + } + end +end + ---@async ---@param opts {repo: string, version: Optional|nil, asset_file: string|fun(release: string):string} function M.release_file(opts) local ctx = installer.context() - local release = (opts.version or ctx.requested_version):or_else_get(function() + local release = _.coalesce(opts.version, ctx.requested_version):or_else_get(function() return client.fetch_latest_release(opts.repo) - :map(function(release) - return release.tag_name - end) + :map(_.prop "tag_name") :get_or_throw "Failed to fetch latest release from GitHub API." end) ---@type string @@ -56,6 +68,22 @@ function M.release_file(opts) } end +---@async +---@param opts {repo: string, version: Optional|nil} +function M.tag(opts) + local ctx = installer.context() + local tag = _.coalesce(opts.version, ctx.requested_version):or_else_get(function() + return client.fetch_latest_tag(opts.repo) + :map(_.prop "name") + :get_or_throw "Failed to fetch latest tag from GitHub API." + end) + + return { + tag = tag, + with_receipt = with_tag_receipt(opts.repo, tag), + } +end + ---@param filename string ---@param processor async fun() local function release_file_processor(filename, processor) diff --git a/lua/nvim-lsp-installer/servers/erlangls/init.lua b/lua/nvim-lsp-installer/servers/erlangls/init.lua index 96c5618c..2ae7403a 100644 --- a/lua/nvim-lsp-installer/servers/erlangls/init.lua +++ b/lua/nvim-lsp-installer/servers/erlangls/init.lua @@ -3,8 +3,8 @@ local path = require "nvim-lsp-installer.core.path" local process = require "nvim-lsp-installer.core.process" local platform = require "nvim-lsp-installer.core.platform" local std = require "nvim-lsp-installer.core.managers.std" -local github_client = require "nvim-lsp-installer.core.managers.github.client" local git = require "nvim-lsp-installer.core.managers.git" +local github = require "nvim-lsp-installer.core.managers.github" local Optional = require "nvim-lsp-installer.core.optional" return function(name, root_dir) @@ -20,14 +20,9 @@ return function(name, root_dir) std.ensure_executable(rebar3, { help_url = "http://rebar3.org/docs/" }) local repo = "erlang-ls/erlang_ls" - ctx.requested_version = ctx.requested_version:or_(function() - return Optional.of(github_client.fetch_latest_tag(repo) - :map(function(tag) - return tag.name - end) - :get_or_throw "Failed to fetch latest tag.") - end) - git.clone({ ("https://github.com/%s.git"):format(repo) }).with_receipt() + local source = github.tag { repo = repo } + source.with_receipt() + git.clone { ("https://github.com/%s.git"):format(repo), version = Optional.of(source.tag) } ctx.spawn[rebar3] { "escriptize" } ctx.spawn[rebar3] { "as", "dap", "escriptize" } diff --git a/lua/nvim-lsp-installer/servers/quick_lint_js/init.lua b/lua/nvim-lsp-installer/servers/quick_lint_js/init.lua index 8b02caa9..f9397f9b 100644 --- a/lua/nvim-lsp-installer/servers/quick_lint_js/init.lua +++ b/lua/nvim-lsp-installer/servers/quick_lint_js/init.lua @@ -4,7 +4,7 @@ local path = require "nvim-lsp-installer.core.path" local functional = require "nvim-lsp-installer.core.functional" local process = require "nvim-lsp-installer.core.process" local std = require "nvim-lsp-installer.core.managers.std" -local github_client = require "nvim-lsp-installer.core.managers.github.client" +local github = require "nvim-lsp-installer.core.managers.github" local coalesce, when = functional.coalesce, functional.when @@ -14,45 +14,27 @@ return function(name, root_dir) root_dir = root_dir, homepage = "https://quick-lint-js.com/", languages = { "javascript" }, - ---@param ctx InstallContext - installer = function(ctx) + ---@async + installer = function() local repo = "quick-lint/quick-lint-js" local release_file = assert( coalesce( - when( - platform.is_mac, - coalesce( - when(platform.arch == "x64", "macos.tar.gz"), - when(platform.arch == "arm64", "macos-aarch64.tar.gz") - ) - ), - when( - platform.is_linux, - coalesce( - when(platform.arch == "x64", "linux.tar.gz"), - when(platform.arch == "arm64", "linux-aarch64.tar.gz"), - when(platform.arch == "arm", "linux-armhf.tar.gz") - ) - ), - when( - platform.is_win, - coalesce( - when(platform.arch == "x64", "windows.zip"), - when(platform.arch == "arm64", "windows-arm64.zip"), - when(platform.arch == "arm", "windows-arm.zip") - ) - ) + when(platform.is.mac_x64, "macos.tar.gz"), + when(platform.is.mac_arm64, "macos-aarch64.tar.gz"), + when(platform.is.linux_x64, "linux.tar.gz"), + when(platform.is.linux_arm64, "linux-aarch64.tar.gz"), + when(platform.is.linux_arm, "linux-armhf.tar.gz"), + when(platform.is.win_x64, "windows.zip"), + when(platform.is.win_arm64, "windows-arm64.zip"), + when(platform.is.win_arm, "windows-arm.zip") ), "Current platform is not supported." ) - local version = ctx.requested_version:or_else_get(function() - return github_client.fetch_latest_tag(repo) - :map(function(tag) - return tag.name - end) - :get_or_throw() - end) - local url = ("https://c.quick-lint-js.com/releases/%s/manual/%s"):format(version, release_file) + + local source = github.tag { repo = repo } + source.with_receipt() + + local url = ("https://c.quick-lint-js.com/releases/%s/manual/%s"):format(source.tag, release_file) platform.when { unix = function() std.download_file(url, "archive.tar.gz") @@ -63,11 +45,6 @@ return function(name, root_dir) std.unzip("archive.zip", ".") end, } - ctx.receipt:with_primary_source { - type = "github_tag", - repo = repo, - tag = version, - } end, default_options = { cmd_env = { |
