aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2024-05-11 21:22:49 +0200
committerGitHub <noreply@github.com>2024-05-11 21:22:49 +0200
commit0f1cb65f436b769733d18b41572f617a1fb41f62 (patch)
tree05da82b94b6abd153c300418e019d4a3401ab5ef /lua/mason-core
parentperf(registry): significantly improve the "file:" protocol performance (#1702) (diff)
downloadmason-0f1cb65f436b769733d18b41572f617a1fb41f62.tar
mason-0f1cb65f436b769733d18b41572f617a1fb41f62.tar.gz
mason-0f1cb65f436b769733d18b41572f617a1fb41f62.tar.bz2
mason-0f1cb65f436b769733d18b41572f617a1fb41f62.tar.lz
mason-0f1cb65f436b769733d18b41572f617a1fb41f62.tar.xz
mason-0f1cb65f436b769733d18b41572f617a1fb41f62.tar.zst
mason-0f1cb65f436b769733d18b41572f617a1fb41f62.zip
fix: fix usage of deprecated Neovim APIs (#1703)
Diffstat (limited to 'lua/mason-core')
-rw-r--r--lua/mason-core/functional/init.lua1
-rw-r--r--lua/mason-core/functional/list.lua20
-rw-r--r--lua/mason-core/functional/type.lua4
-rw-r--r--lua/mason-core/installer/registry/init.lua2
-rw-r--r--lua/mason-core/installer/registry/util.lua2
-rw-r--r--lua/mason-core/spawn.lua4
6 files changed, 29 insertions, 4 deletions
diff --git a/lua/mason-core/functional/init.lua b/lua/mason-core/functional/init.lua
index 87a5f325..d377d2db 100644
--- a/lua/mason-core/functional/init.lua
+++ b/lua/mason-core/functional/init.lua
@@ -133,6 +133,7 @@ _.assoc = tbl.assoc
local typ = lazy_require "mason-core.functional.type"
_.is_nil = typ.is_nil
_.is = typ.is
+_.is_list = typ.is_list
-- TODO do something else with these
diff --git a/lua/mason-core/functional/list.lua b/lua/mason-core/functional/list.lua
index ff2e18c2..b2c48293 100644
--- a/lua/mason-core/functional/list.lua
+++ b/lua/mason-core/functional/list.lua
@@ -74,7 +74,25 @@ _.filter = fun.curryN(vim.tbl_filter, 2)
---@type fun(map_fn: (fun(item: T): U), items: T[]): U[]
_.map = fun.curryN(vim.tbl_map, 2)
-_.flatten = fun.curryN(vim.tbl_flatten, 1)
+---@param tbl table
+---@return table
+_.flatten = function(tbl)
+ local result = {}
+ --- @param _tbl table<any,any>
+ local function _tbl_flatten(_tbl)
+ local n = #_tbl
+ for i = 1, n do
+ local v = _tbl[i]
+ if type(v) == "table" then
+ _tbl_flatten(v)
+ elseif v then
+ table.insert(result, v)
+ end
+ end
+ end
+ _tbl_flatten(tbl)
+ return result
+end
---@generic T
---@param map_fn fun(item: T): Optional
diff --git a/lua/mason-core/functional/type.lua b/lua/mason-core/functional/type.lua
index e3bf5fe7..b15a2025 100644
--- a/lua/mason-core/functional/type.lua
+++ b/lua/mason-core/functional/type.lua
@@ -11,4 +11,8 @@ _.is = fun.curryN(function(typ, value)
return type(value) == typ
end, 2)
+---@param value any
+---@return boolean
+_.is_list = vim.fn.has "nvim-0.10" and vim.islist or vim.tbl_islist
+
return _
diff --git a/lua/mason-core/installer/registry/init.lua b/lua/mason-core/installer/registry/init.lua
index e97a8430..e7c796e9 100644
--- a/lua/mason-core/installer/registry/init.lua
+++ b/lua/mason-core/installer/registry/init.lua
@@ -54,7 +54,7 @@ end
local function upsert(dst, src)
for k, v in pairs(src) do
if type(v) == "table" then
- if vim.tbl_islist(v) then
+ if _.is_list(v) then
dst[k] = _.concat(v, dst[k] or {})
else
dst[k] = upsert(dst[k] or {}, src[k])
diff --git a/lua/mason-core/installer/registry/util.lua b/lua/mason-core/installer/registry/util.lua
index d0045a3e..b3735c9c 100644
--- a/lua/mason-core/installer/registry/util.lua
+++ b/lua/mason-core/installer/registry/util.lua
@@ -12,7 +12,7 @@ local M = {}
---@param opts PackageInstallOpts
---@return Result # Result<T>
function M.coalesce_by_target(candidates, opts)
- if not vim.tbl_islist(candidates) then
+ if not _.is_list(candidates) then
return Result.success(candidates)
end
return Optional.of_nilable(_.find_first(function(asset)
diff --git a/lua/mason-core/spawn.lua b/lua/mason-core/spawn.lua
index c6f06d81..33af9ea4 100644
--- a/lua/mason-core/spawn.lua
+++ b/lua/mason-core/spawn.lua
@@ -5,6 +5,8 @@ local log = require "mason-core.log"
local platform = require "mason-core.platform"
local process = require "mason-core.process"
+local is_not_nil = _.complement(_.equals(vim.NIL))
+
---@alias JobSpawn table<string, async fun(opts: SpawnArgs): Result>
---@type JobSpawn
local spawn = {
@@ -17,7 +19,7 @@ local spawn = {
luarocks = (platform.is.win and vim.fn.executable "luarocks.bat" == 1) and "luarocks.bat" or "luarocks",
rebar3 = platform.is.win and "rebar3.cmd" or "rebar3",
},
- _flatten_cmd_args = _.compose(_.filter(_.complement(_.equals(vim.NIL))), _.flatten),
+ _flatten_cmd_args = _.compose(_.filter(is_not_nil), _.flatten),
}
local function Failure(err, cmd)