mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
docs(lua): more improvements (#24387)
* docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes <justinkz@gmail.com> --------- Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
@@ -8,6 +8,45 @@
|
||||
|
||||
vim = vim or {}
|
||||
|
||||
local function _id(v)
|
||||
return v
|
||||
end
|
||||
|
||||
local deepcopy
|
||||
|
||||
local deepcopy_funcs = {
|
||||
table = function(orig, cache)
|
||||
if cache[orig] then
|
||||
return cache[orig]
|
||||
end
|
||||
local copy = {}
|
||||
|
||||
cache[orig] = copy
|
||||
local mt = getmetatable(orig)
|
||||
for k, v in pairs(orig) do
|
||||
copy[deepcopy(k, cache)] = deepcopy(v, cache)
|
||||
end
|
||||
return setmetatable(copy, mt)
|
||||
end,
|
||||
number = _id,
|
||||
string = _id,
|
||||
['nil'] = _id,
|
||||
boolean = _id,
|
||||
['function'] = _id,
|
||||
}
|
||||
|
||||
deepcopy = function(orig, _cache)
|
||||
local f = deepcopy_funcs[type(orig)]
|
||||
if f then
|
||||
return f(orig, _cache or {})
|
||||
else
|
||||
if type(orig) == 'userdata' and orig == vim.NIL then
|
||||
return vim.NIL
|
||||
end
|
||||
error('Cannot deepcopy object of type ' .. type(orig))
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns a deep copy of the given object. Non-table objects are copied as
|
||||
--- in a typical Lua assignment, whereas table objects are copied recursively.
|
||||
--- Functions are naively copied, so functions in the copied table point to the
|
||||
@@ -17,45 +56,9 @@ vim = vim or {}
|
||||
---@generic T: table
|
||||
---@param orig T Table to copy
|
||||
---@return T Table of copied keys and (nested) values.
|
||||
function vim.deepcopy(orig) end -- luacheck: no unused
|
||||
vim.deepcopy = (function()
|
||||
local function _id(v)
|
||||
return v
|
||||
end
|
||||
|
||||
local deepcopy_funcs = {
|
||||
table = function(orig, cache)
|
||||
if cache[orig] then
|
||||
return cache[orig]
|
||||
end
|
||||
local copy = {}
|
||||
|
||||
cache[orig] = copy
|
||||
local mt = getmetatable(orig)
|
||||
for k, v in pairs(orig) do
|
||||
copy[vim.deepcopy(k, cache)] = vim.deepcopy(v, cache)
|
||||
end
|
||||
return setmetatable(copy, mt)
|
||||
end,
|
||||
number = _id,
|
||||
string = _id,
|
||||
['nil'] = _id,
|
||||
boolean = _id,
|
||||
['function'] = _id,
|
||||
}
|
||||
|
||||
return function(orig, cache)
|
||||
local f = deepcopy_funcs[type(orig)]
|
||||
if f then
|
||||
return f(orig, cache or {})
|
||||
else
|
||||
if type(orig) == 'userdata' and orig == vim.NIL then
|
||||
return vim.NIL
|
||||
end
|
||||
error('Cannot deepcopy object of type ' .. type(orig))
|
||||
end
|
||||
end
|
||||
end)()
|
||||
function vim.deepcopy(orig)
|
||||
return deepcopy(orig)
|
||||
end
|
||||
|
||||
--- Splits a string at each instance of a separator.
|
||||
---
|
||||
@@ -318,7 +321,6 @@ function vim.tbl_isempty(t)
|
||||
end
|
||||
|
||||
--- We only merge empty tables or tables that are not an array (indexed by integers)
|
||||
---@private
|
||||
local function can_merge(v)
|
||||
return type(v) == 'table' and (vim.tbl_isempty(v) or not vim.tbl_isarray(v))
|
||||
end
|
||||
@@ -770,7 +772,6 @@ do
|
||||
return type(val) == t or (t == 'callable' and vim.is_callable(val))
|
||||
end
|
||||
|
||||
---@private
|
||||
local function is_valid(opt)
|
||||
if type(opt) ~= 'table' then
|
||||
return false, string.format('opt: expected table, got %s', type(opt))
|
||||
|
Reference in New Issue
Block a user