diff options
| author | William Boman <william@redwill.se> | 2023-04-18 01:16:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-18 01:16:39 +0200 |
| commit | a0604613f5887ba14722d710e2b9290b3894e8db (patch) | |
| tree | 46995dde77d00b96b24dbfe4212583e2e745f02f /lua/mason-core/installer/registry/expr.lua | |
| parent | feat: add require("mason").has_setup flag (#1226) (diff) | |
| download | mason-a0604613f5887ba14722d710e2b9290b3894e8db.tar mason-a0604613f5887ba14722d710e2b9290b3894e8db.tar.gz mason-a0604613f5887ba14722d710e2b9290b3894e8db.tar.bz2 mason-a0604613f5887ba14722d710e2b9290b3894e8db.tar.lz mason-a0604613f5887ba14722d710e2b9290b3894e8db.tar.xz mason-a0604613f5887ba14722d710e2b9290b3894e8db.tar.zst mason-a0604613f5887ba14722d710e2b9290b3894e8db.zip | |
refactor(expr): remove redundant core filters and always stringify reduced value (#1227)
The removed filters are not used by mason-registry and are too Lua-specific in nature.
Diffstat (limited to 'lua/mason-core/installer/registry/expr.lua')
| -rw-r--r-- | lua/mason-core/installer/registry/expr.lua | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lua/mason-core/installer/registry/expr.lua b/lua/mason-core/installer/registry/expr.lua index 5900f576..5dc016eb 100644 --- a/lua/mason-core/installer/registry/expr.lua +++ b/lua/mason-core/installer/registry/expr.lua @@ -13,17 +13,27 @@ local parse_expr = _.compose( _.split "|" ) +---@param predicate fun(value: string): boolean +---@param value string +local take_if = _.curryN(function(predicate, value) + return predicate(value) and value or nil +end, 2) + +---@param predicate fun(value: string): boolean +---@param value string +local take_if_not = _.curryN(function(predicate, value) + return (not predicate(value)) and value or nil +end, 2) + local FILTERS = { - format = _.format, - gsub = _.gsub, + equals = _.equals, + not_equals = _.not_equals, + strip_prefix = _.trim_start_matches, + strip_suffix = _.trim_end_matches, + take_if = take_if, + take_if_not = take_if_not, to_lower = _.to_lower, to_upper = _.to_upper, - trim = _.trim, - trim_start = _.trim_start, - trim_end = _.trim_end, - strip_prefix = _.strip_prefix, - strip_suffix = _.strip_suffix, - tostring = tostring, } ---@generic T : table @@ -60,7 +70,9 @@ function M.interpolate(str, ctx) return filter end, components.filters) - return _.reduce(_.apply_to, value, filters) or "" + local reduced_value = _.reduce(_.apply_to, value, filters) + + return reduced_value ~= nil and tostring(reduced_value) or "" end, str) end) end @@ -68,7 +80,7 @@ end ---@generic T : table ---@param tbl T ---@param ctx table ----@return T +---@return Result # Result<T> function M.tbl_interpolate(tbl, ctx) return Result.try(function(try) local interpolated = {} |
