feat(plugin): opts_extend can be a list of dotted keys that will be extended instead of merged

This commit is contained in:
Folke Lemaitre 2024-06-07 09:02:52 +02:00
parent 89ddc59d19
commit 1f7b720cff
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 52 additions and 1 deletions

View file

@ -428,4 +428,35 @@ function M.lazy_require(module)
})
end
---@param t table
---@param key string|string[]
---@return any
function M.key_get(t, key)
local path = type(key) == "table" and key or vim.split(key, ".", true)
local value = t
for _, k in ipairs(path) do
if type(value) ~= "table" then
return value
end
value = value[k]
end
return value
end
---@param t table
---@param key string|string[]
---@param value any
function M.key_set(t, key, value)
local path = type(key) == "table" and key or vim.split(key, ".", true)
local last = t
for i = 1, #path - 1 do
local k = path[i]
if type(last[k]) ~= "table" then
last[k] = {}
end
last = last[k]
end
last[path[#path]] = value
end
return M