mirror of
https://github.com/neovim/neovim.git
synced 2026-02-04 11:04:30 +00:00
feat(lua): vim.tbl_contains supports general tables and predicates (#23040)
* feat(lua): vim.tbl_contains supports general tables and predicates Problem: `vim.tbl_contains` only works for list-like tables (integer keys without gaps) and primitive values (in particular, not for nested tables). Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new `vim.tbl_contains` that works for general tables and optionally allows `value` to be a predicate function that is checked for every key.
This commit is contained in:
@@ -171,7 +171,7 @@ local function for_each_buffer_client(bufnr, fn, restrict_client_ids)
|
||||
if restrict_client_ids and #restrict_client_ids > 0 then
|
||||
local filtered_client_ids = {}
|
||||
for client_id in pairs(client_ids) do
|
||||
if vim.tbl_contains(restrict_client_ids, client_id) then
|
||||
if vim.list_contains(restrict_client_ids, client_id) then
|
||||
filtered_client_ids[client_id] = true
|
||||
end
|
||||
end
|
||||
@@ -2186,7 +2186,7 @@ function lsp.formatexpr(opts)
|
||||
opts = opts or {}
|
||||
local timeout_ms = opts.timeout_ms or 500
|
||||
|
||||
if vim.tbl_contains({ 'i', 'R', 'ic', 'ix' }, vim.fn.mode()) then
|
||||
if vim.list_contains({ 'i', 'R', 'ic', 'ix' }, vim.fn.mode()) then
|
||||
-- `formatexpr` is also called when exceeding `textwidth` in insert mode
|
||||
-- fall back to internal formatting
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user