refactor(lua): rename tbl_isarray => isarray

tbl_isarray was not released yet, so it will not go through
a deprecation cycle.

ref #24572
This commit is contained in:
Justin M. Keyes
2024-04-21 17:29:10 +02:00
parent d9d890562e
commit 5c8dfb0e37
5 changed files with 47 additions and 41 deletions

View File

@@ -172,8 +172,8 @@ LUA
- vim.register_keystroke_callback() Use |vim.on_key()| instead. - vim.register_keystroke_callback() Use |vim.on_key()| instead.
- *vim.pretty_print()* Use |vim.print()| instead. - *vim.pretty_print()* Use |vim.print()| instead.
- *vim.loop* Use |vim.uv| instead. - *vim.loop* Use |vim.uv| instead.
- *vim.tbl_islist()* Use |vim.islist()| instead.
- *vim.tbl_add_reverse_lookup()* - *vim.tbl_add_reverse_lookup()*
- *vim.tbl_islist()* Use |vim.islist()| instead.
NORMAL COMMANDS NORMAL COMMANDS
- *]f* *[f* Same as "gf". - *]f* *[f* Same as "gf".

View File

@@ -2029,6 +2029,26 @@ vim.is_callable({f}) *vim.is_callable()*
Return: ~ Return: ~
(`boolean`) `true` if `f` is callable, else `false` (`boolean`) `true` if `f` is callable, else `false`
vim.isarray({t}) *vim.isarray()*
Tests if `t` is an "array": a table indexed only by integers (potentially
non-contiguous).
If the indexes start from 1 and are contiguous then the array is also a
list. |vim.islist()|
Empty table `{}` is an array, unless it was created by |vim.empty_dict()|
or returned as a dict-like |API| or Vimscript result, for example from
|rpcrequest()| or |vim.fn|.
Parameters: ~
• {t} (`table?`)
Return: ~
(`boolean`) `true` if array-like table, else `false`.
See also: ~
• https://github.com/openresty/luajit2#tableisarray
vim.islist({t}) *vim.islist()* vim.islist({t}) *vim.islist()*
Tests if `t` is a "list": a table indexed only by contiguous integers Tests if `t` is a "list": a table indexed only by contiguous integers
starting from 1 (what |lua-length| calls a "regular array"). starting from 1 (what |lua-length| calls a "regular array").
@@ -2044,7 +2064,7 @@ vim.islist({t}) *vim.islist()*
(`boolean`) `true` if list-like table, else `false`. (`boolean`) `true` if list-like table, else `false`.
See also: ~ See also: ~
• |vim.tbl_isarray()| • |vim.isarray()|
vim.list_contains({t}, {value}) *vim.list_contains()* vim.list_contains({t}, {value}) *vim.list_contains()*
Checks if a list-like table (integer keys without gaps) contains `value`. Checks if a list-like table (integer keys without gaps) contains `value`.
@@ -2296,26 +2316,6 @@ vim.tbl_get({o}, {...}) *vim.tbl_get()*
Return: ~ Return: ~
(`any`) Nested value indexed by key (if it exists), else nil (`any`) Nested value indexed by key (if it exists), else nil
vim.tbl_isarray({t}) *vim.tbl_isarray()*
Tests if `t` is an "array": a table indexed only by integers (potentially
non-contiguous).
If the indexes start from 1 and are contiguous then the array is also a
list. |vim.islist()|
Empty table `{}` is an array, unless it was created by |vim.empty_dict()|
or returned as a dict-like |API| or Vimscript result, for example from
|rpcrequest()| or |vim.fn|.
Parameters: ~
• {t} (`table`)
Return: ~
(`boolean`) `true` if array-like table, else `false`.
See also: ~
• https://github.com/openresty/luajit2#tableisarray
vim.tbl_isempty({t}) *vim.tbl_isempty()* vim.tbl_isempty({t}) *vim.tbl_isempty()*
Checks if a table is empty. Checks if a table is empty.

View File

@@ -25,7 +25,7 @@ The following changes may require adaptations in user config or plugins.
• |vim.islist()| now checks whether a table is actually list-like (i.e., • |vim.islist()| now checks whether a table is actually list-like (i.e.,
has integer keys without gaps and starting from 1). For the previous has integer keys without gaps and starting from 1). For the previous
behavior (only check for integer keys, allow gaps or not starting with 1), behavior (only check for integer keys, allow gaps or not starting with 1),
use |vim.tbl_isarray()|. use |vim.isarray()|.
• "#" followed by a digit no longer stands for a function key at the start of • "#" followed by a digit no longer stands for a function key at the start of
the lhs of a mapping. the lhs of a mapping.
@@ -155,7 +155,7 @@ unreleased features on Nvim HEAD.
• Removed vim.iter.map(), vim.iter.filter(), vim.iter.totable(). • Removed vim.iter.map(), vim.iter.filter(), vim.iter.totable().
• Renamed vim.tbl_islist() to vim.islist(). • Renamed vim.tbl_isarray() to vim.isarray().
============================================================================== ==============================================================================
NEW FEATURES *news-features* NEW FEATURES *news-features*
@@ -563,7 +563,7 @@ release.
populated. Background color detection is now performed in Lua by the Nvim populated. Background color detection is now performed in Lua by the Nvim
core, not the TUI. core, not the TUI.
vim.shared functions: Lua stdlib:
- |vim.tbl_add_reverse_lookup()| - |vim.tbl_add_reverse_lookup()|
- |vim.tbl_islist()| - |vim.tbl_islist()|

View File

@@ -356,7 +356,7 @@ end
--- We only merge empty tables or tables that are not an array (indexed by integers) --- We only merge empty tables or tables that are not an array (indexed by integers)
local function can_merge(v) local function can_merge(v)
return type(v) == 'table' and (vim.tbl_isempty(v) or not vim.tbl_isarray(v)) return type(v) == 'table' and (vim.tbl_isempty(v) or not vim.isarray(v))
end end
local function tbl_extend(behavior, deep_extend, ...) local function tbl_extend(behavior, deep_extend, ...)
@@ -502,7 +502,7 @@ end
--- ---
---@param o table Table to index ---@param o table Table to index
---@param ... any Optional keys (0 or more, variadic) via which to index the table ---@param ... any Optional keys (0 or more, variadic) via which to index the table
---@return any : Nested value indexed by key (if it exists), else nil ---@return any # Nested value indexed by key (if it exists), else nil
function vim.tbl_get(o, ...) function vim.tbl_get(o, ...)
local keys = { ... } local keys = { ... }
if #keys == 0 then if #keys == 0 then
@@ -599,6 +599,12 @@ function vim.spairs(t)
t t
end end
--- @deprecated
function vim.tbl_isarray()
vim.deprecate('vim.tbl_isarray', 'vim.isarray', '0.10-dev')
error('vim.tbl_isarray was renamed to vim.isarray')
end
--- Tests if `t` is an "array": a table indexed _only_ by integers (potentially non-contiguous). --- Tests if `t` is an "array": a table indexed _only_ by integers (potentially non-contiguous).
--- ---
--- If the indexes start from 1 and are contiguous then the array is also a list. |vim.islist()| --- If the indexes start from 1 and are contiguous then the array is also a list. |vim.islist()|
@@ -608,9 +614,9 @@ end
--- ---
---@see https://github.com/openresty/luajit2#tableisarray ---@see https://github.com/openresty/luajit2#tableisarray
--- ---
---@param t table ---@param t? table
---@return boolean `true` if array-like table, else `false`. ---@return boolean `true` if array-like table, else `false`.
function vim.tbl_isarray(t) function vim.isarray(t)
if type(t) ~= 'table' then if type(t) ~= 'table' then
return false return false
end end
@@ -652,7 +658,7 @@ end
--- Empty table `{}` is a list, unless it was created by |vim.empty_dict()| or returned as --- Empty table `{}` is a list, unless it was created by |vim.empty_dict()| or returned as
--- a dict-like |API| or Vimscript result, for example from |rpcrequest()| or |vim.fn|. --- a dict-like |API| or Vimscript result, for example from |rpcrequest()| or |vim.fn|.
--- ---
---@see |vim.tbl_isarray()| ---@see |vim.isarray()|
--- ---
---@param t? table ---@param t? table
---@return boolean `true` if list-like table, else `false`. ---@return boolean `true` if list-like table, else `false`.

View File

@@ -825,17 +825,17 @@ describe('lua stdlib', function()
) )
end) end)
it('vim.tbl_isarray', function() it('vim.isarray', function()
eq(true, exec_lua('return vim.tbl_isarray({})')) eq(true, exec_lua('return vim.isarray({})'))
eq(false, exec_lua('return vim.tbl_isarray(vim.empty_dict())')) eq(false, exec_lua('return vim.isarray(vim.empty_dict())'))
eq(true, exec_lua("return vim.tbl_isarray({'a', 'b', 'c'})")) eq(true, exec_lua("return vim.isarray({'a', 'b', 'c'})"))
eq(false, exec_lua("return vim.tbl_isarray({'a', '32', a='hello', b='baz'})")) eq(false, exec_lua("return vim.isarray({'a', '32', a='hello', b='baz'})"))
eq(false, exec_lua("return vim.tbl_isarray({1, a='hello', b='baz'})")) eq(false, exec_lua("return vim.isarray({1, a='hello', b='baz'})"))
eq(false, exec_lua("return vim.tbl_isarray({a='hello', b='baz', 1})")) eq(false, exec_lua("return vim.isarray({a='hello', b='baz', 1})"))
eq(false, exec_lua("return vim.tbl_isarray({1, 2, nil, a='hello'})")) eq(false, exec_lua("return vim.isarray({1, 2, nil, a='hello'})"))
eq(true, exec_lua('return vim.tbl_isarray({1, 2, nil, 4})')) eq(true, exec_lua('return vim.isarray({1, 2, nil, 4})'))
eq(true, exec_lua('return vim.tbl_isarray({nil, 2, 3, 4})')) eq(true, exec_lua('return vim.isarray({nil, 2, 3, 4})'))
eq(false, exec_lua('return vim.tbl_isarray({1, [1.5]=2, [3]=3})')) eq(false, exec_lua('return vim.isarray({1, [1.5]=2, [3]=3})'))
end) end)
it('vim.islist', function() it('vim.islist', function()