mirror of
https://github.com/neovim/neovim.git
synced 2025-12-03 15:33:03 +00:00
lua/stdlib: Load runtime modules on-demand
Instead of eager-loading during plugin/* sourcing, define runtime modules such as `vim.inspect` as lazy builtins. Otherwise non-builtin Lua modules such as `vim.inspect` would not be available during startup (init.vim, `-c`, `--cmd`, …). ref #6580 ref #8677
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
lua vim.inspect = require("vim.inspect")
|
|
||||||
@@ -152,6 +152,14 @@ local function gsplit(s, sep, plain)
|
|||||||
end
|
end
|
||||||
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 function split(s,sep,plain)
|
||||||
local t={} for c in gsplit(s, sep, plain) do table.insert(t,c) end
|
local t={} for c in gsplit(s, sep, plain) do table.insert(t,c) end
|
||||||
return t
|
return t
|
||||||
@@ -196,6 +204,7 @@ local module = {
|
|||||||
split = split,
|
split = split,
|
||||||
gsplit = gsplit,
|
gsplit = gsplit,
|
||||||
deepcopy = deepcopy,
|
deepcopy = deepcopy,
|
||||||
|
inspect = inspect,
|
||||||
}
|
}
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
|||||||
@@ -169,16 +169,14 @@ end)
|
|||||||
|
|
||||||
describe("vim.inspect", function()
|
describe("vim.inspect", function()
|
||||||
it('works', function()
|
it('works', function()
|
||||||
command("source runtime/plugin/nvim.vim")
|
|
||||||
-- just make sure it basically works, it has its own test suite
|
-- just make sure it basically works, it has its own test suite
|
||||||
local inspect = function(t, opts)
|
local inspect = function(t, opts)
|
||||||
return meths.execute_lua('return vim.inspect(...)', { t, opts })
|
return meths.execute_lua('return vim.inspect(...)', { t, opts })
|
||||||
end
|
end
|
||||||
|
|
||||||
eq('2', inspect(2))
|
eq('2', inspect(2))
|
||||||
|
eq('{+a = {+b = 1+}+}',
|
||||||
local i = inspect({ a = { b = 1 } }, { newline = '+', indent = '' })
|
inspect({ a = { b = 1 } }, { newline = '+', indent = '' }))
|
||||||
eq('{+a = {+b = 1+}+}', i)
|
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user