mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #9505 from bfredl/inspect
lua: expose full interface of vim.inspect and add test
This commit is contained in:
commit
387ab4f706
@ -152,14 +152,6 @@ local function gsplit(s, sep, plain)
|
||||
end
|
||||
end
|
||||
|
||||
local inspect = (function()
|
||||
local f
|
||||
return function(...)
|
||||
if f == nil then f = require('vim.inspect') end
|
||||
return f(...)
|
||||
end
|
||||
end)()
|
||||
|
||||
local function split(s,sep,plain)
|
||||
local t={} for c in gsplit(s, sep, plain) do table.insert(t,c) end
|
||||
return t
|
||||
@ -195,6 +187,13 @@ deepcopy = function(orig)
|
||||
return deepcopy_funcs[type(orig)](orig)
|
||||
end
|
||||
|
||||
local function __index(table, key)
|
||||
if key == "inspect" then
|
||||
table.inspect = require("vim.inspect")
|
||||
return table.inspect
|
||||
end
|
||||
end
|
||||
|
||||
local module = {
|
||||
_update_package_paths = _update_package_paths,
|
||||
_os_proc_children = _os_proc_children,
|
||||
@ -204,7 +203,10 @@ local module = {
|
||||
split = split,
|
||||
gsplit = gsplit,
|
||||
deepcopy = deepcopy,
|
||||
inspect = inspect,
|
||||
}
|
||||
|
||||
setmetatable(module, {
|
||||
__index = __index
|
||||
})
|
||||
|
||||
return module
|
||||
|
@ -176,6 +176,16 @@ describe("vim.inspect", function()
|
||||
eq('2', inspect(2))
|
||||
eq('{+a = {+b = 1+}+}',
|
||||
inspect({ a = { b = 1 } }, { newline = '+', indent = '' }))
|
||||
|
||||
-- special value vim.inspect.KEY works
|
||||
eq('{ KEY_a = "x", KEY_b = "y"}', meths.execute_lua([[
|
||||
return vim.inspect({a="x", b="y"}, {newline = '', process = function(item, path)
|
||||
if path[#path] == vim.inspect.KEY then
|
||||
return 'KEY_'..item
|
||||
end
|
||||
return item
|
||||
end})
|
||||
]], {}))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user