-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(providers): fix some client providers and add some more (#1354)
- Loading branch information
1 parent
9bbd209
commit 6f44955
Showing
6 changed files
with
59 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local _ = require "mason-core.functional" | ||
local spawn = require "mason-core.spawn" | ||
|
||
---@type GolangProvider | ||
return { | ||
get_all_versions = function(pkg) | ||
return spawn | ||
.go({ | ||
"list", | ||
"-json", | ||
"-m", | ||
"-versions", | ||
pkg, | ||
}) | ||
:map(_.prop "stdout") | ||
:map_catching(vim.json.decode) | ||
:map(_.prop "Versions") | ||
:map(_.reverse) | ||
end, | ||
} |
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,29 @@ | ||
local Optional = require "mason-core.optional" | ||
local _ = require "mason-core.functional" | ||
local spawn = require "mason-core.spawn" | ||
|
||
---@param gem string | ||
---@param output string "$ gem list" output | ||
local parse_gem_versions = _.curryN(function(gem, output) | ||
local lines = _.split("\n", output) | ||
return Optional.of_nilable(_.find_first(_.starts_with(gem), lines)) | ||
:map(_.compose(_.head, _.match "%((.+)%)$")) | ||
:map(_.split ", ") | ||
:ok_or "Failed to parse gem list output." | ||
end, 2) | ||
|
||
---@async | ||
---@param gem string | ||
local function get_all_versions(gem) | ||
return spawn.gem({ "list", gem, "--remote", "--all" }):map(_.prop "stdout"):and_then(parse_gem_versions(gem)) | ||
end | ||
|
||
---@type RubyGemsProvider | ||
return { | ||
get_latest_version = function(gem) | ||
return get_all_versions(gem):map(_.head) | ||
end, | ||
get_all_versions = function(gem) | ||
return get_all_versions(gem) | ||
end, | ||
} |