aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/core/managers
diff options
context:
space:
mode:
Diffstat (limited to 'lua/nvim-lsp-installer/core/managers')
-rw-r--r--lua/nvim-lsp-installer/core/managers/git/init.lua5
-rw-r--r--lua/nvim-lsp-installer/core/managers/github/init.lua36
2 files changed, 35 insertions, 6 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)