Skip to content

Commit

Permalink
fix(providers): fix some client providers and add some more (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamboman committed Jun 13, 2023
1 parent 9bbd209 commit 6f44955
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
3 changes: 0 additions & 3 deletions lua/mason/providers/client/gh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ return {
get_all_release_versions = function(repo)
return client.fetch_all_releases(repo):map(_.map(_.prop "tag_name"))
end,
get_latest_tag = function(repo)
return Result.failure "Unimplemented"
end,
get_all_tags = function(repo)
return client.fetch_all_tags(repo):map(_.map(_.compose(_.gsub("^refs/tags/", ""), _.prop "ref")))
end,
Expand Down
20 changes: 20 additions & 0 deletions lua/mason/providers/client/golang.lua
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,
}
2 changes: 2 additions & 0 deletions lua/mason/providers/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ return {
github = require "mason.providers.client.gh",
npm = require "mason.providers.client.npm",
pypi = require "mason.providers.client.pypi",
rubygems = require "mason.providers.client.rubygems",
golang = require "mason.providers.client.golang",
}
6 changes: 5 additions & 1 deletion lua/mason/providers/client/npm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ return {
:map(_.pick { "name", "version" })
end,
get_all_versions = function(pkg)
return spawn.npm({ "view", pkg, "versions" }):map(_.prop "stdout"):map_catching(vim.json.decode)
return spawn
.npm({ "view", "--json", pkg, "versions" })
:map(_.prop "stdout")
:map_catching(vim.json.decode)
:map(_.reverse)
end,
}
5 changes: 3 additions & 2 deletions lua/mason/providers/client/pypi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ local function get_all_versions(pkg)
"--use-deprecated=legacy-resolver", -- for pip >= 20.3
("%s=="):format(pkg), -- invalid version specifier to trigger the wanted error message
})
:map_err(_.compose(_.split ", ", _.head, _.match "%(from versions: (.+)%)", _.prop "stderr"))
:recover(_.identity)
:recover(_.prop "stderr")
:map(_.compose(_.split ", ", _.head, _.match "%(from versions: (.+)%)"))
:map(_.reverse)
end

---@param pkg string
Expand Down
29 changes: 29 additions & 0 deletions lua/mason/providers/client/rubygems.lua
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,
}

0 comments on commit 6f44955

Please sign in to comment.