aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/managers
diff options
context:
space:
mode:
Diffstat (limited to 'lua/mason-core/managers')
-rw-r--r--lua/mason-core/managers/cargo/init.lua167
-rw-r--r--lua/mason-core/managers/github/client.lua26
2 files changed, 143 insertions, 50 deletions
diff --git a/lua/mason-core/managers/cargo/init.lua b/lua/mason-core/managers/cargo/init.lua
index b8cd4fa7..8890daf6 100644
--- a/lua/mason-core/managers/cargo/init.lua
+++ b/lua/mason-core/managers/cargo/init.lua
@@ -5,6 +5,8 @@ local a = require "mason-core.async"
local Optional = require "mason-core.optional"
local installer = require "mason-core.installer"
local client = require "mason-core.managers.cargo.client"
+local github = require "mason-core.managers.github"
+local github_client = require "mason-core.managers.github.client"
local _ = require "mason-core.functional"
local get_bin_path = _.compose(path.concat, function(executable)
@@ -23,32 +25,50 @@ local M = {}
---@async
---@param crate string The crate to install.
----@param opts {git: boolean | string, features: string?, bin: string[]? }?
+---@param opts { git: { url: string, tag: boolean? }, features: string?, bin: string[]? }?
function M.crate(crate, opts)
return function()
- M.install(crate, opts).with_receipt()
+ if opts and opts.git and opts.git.tag then
+ local ctx = installer.context()
+ local repo = assert(opts.git.url:match "^https://github%.com/(.+)$", "git url needs to be github.com")
+ local source = github.tag { repo = repo }
+ source.with_receipt()
+ ctx.requested_version = Optional.of(source.tag)
+ M.install(crate, opts)
+ else
+ M.install(crate, opts).with_receipt()
+ end
end
end
---@async
---@param crate string The crate to install.
----@param opts {git: boolean | string, features: string?, bin: string[]? }?
+---@param opts { git: { url: string, tag: boolean? }, features: string?, bin: string[]? }?
function M.install(crate, opts)
local ctx = installer.context()
opts = opts or {}
- ctx.requested_version:if_present(function()
- assert(not opts.git, "Providing a version when installing a git crate is not allowed.")
- end)
- ---@type string | string[]
- local final_crate = crate
+ local version
if opts.git then
- final_crate = { "--git" }
- if type(opts.git) == "string" then
- table.insert(final_crate, opts.git)
+ if opts.git.tag then
+ assert(ctx.requested_version:is_present(), "version is required when installing tagged git crate.")
end
- table.insert(final_crate, crate)
+ version = ctx.requested_version
+ :map(function(version)
+ if opts.git.tag then
+ return { "--tag", version }
+ else
+ return { "--rev", version }
+ end
+ end)
+ :or_else(vim.NIL)
+ else
+ version = ctx.requested_version
+ :map(function(version)
+ return { "--version", version }
+ end)
+ :or_else(vim.NIL)
end
ctx.spawn.cargo {
@@ -56,13 +76,10 @@ function M.install(crate, opts)
"--root",
".",
"--locked",
- ctx.requested_version
- :map(function(version)
- return { "--version", version }
- end)
- :or_else(vim.NIL),
+ version,
+ opts.git and { "--git", opts.git.url } or vim.NIL,
opts.features and { "--features", opts.features } or vim.NIL,
- final_crate,
+ crate,
}
if opts.bin then
@@ -76,42 +93,39 @@ function M.install(crate, opts)
}
end