-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: consolidate Lua registry sources and the Package API
This removes the following APIs: - `Package:check_new_version()`. Instead use the new `Package:get_latest_version()`. This has a breaking change in the following APIs: - `Package:get_installed_version()` now no longer takes a callback but instead returns the installed version or `nil` if not installed. To handle these breaking changes in plugins, leverage the `mason.version` module, for example: ```lua local mason_version = require("mason.version") local registry = require("mason-registry") local pkg = registry.get_package("rust-analyzer") if mason_version.MAJOR_VERSION < 2 then -- before pkg:check_new_version(function (success, new_version) -- … end) pkg:get_installed_version(function (success, installed_version) -- … end) else -- after local new_version = pkg:get_latest_version() local installed_version = pkg:get_installed_version() fi ```
- Loading branch information
1 parent
6c49fdf
commit 822821a
Showing
18 changed files
with
307 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local Result = require "mason-core.result" | ||
local _ = require "mason-core.functional" | ||
|
||
local M = {} | ||
|
||
---@param source RegistryPackageSource | ||
---@param purl Purl | ||
function M.parse(source, purl) | ||
if type(source.install) ~= "function" and type((getmetatable(source.install) or {}).__call) ~= "function" then | ||
return Result.failure "source.install is not a function." | ||
end | ||
|
||
---@class ParsedMasonSource : ParsedPackageSource | ||
local parsed_source = { | ||
purl = purl, | ||
---@type async fun(ctx: InstallContext, purl: Purl) | ||
install = source.install, | ||
} | ||
|
||
return Result.success(parsed_source) | ||
end | ||
|
||
---@async | ||
---@param ctx InstallContext | ||
---@param source ParsedMasonSource | ||
function M.install(ctx, source) | ||
ctx.spawn.strict_mode = true | ||
return Result.pcall(source.install, ctx, source.purl) | ||
:on_success(function() | ||
ctx.spawn.strict_mode = false | ||
end) | ||
:on_failure(function() | ||
ctx.spawn.strict_mode = false | ||
end) | ||
end | ||
|
||
---@async | ||
---@param purl Purl | ||
function M.get_versions(purl) | ||
return Result.failure "Unimplemented." | ||
end | ||
|
||
return M |
Oops, something went wrong.