mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
lua: make vim.inspect available early so it can be used for path debugging
This commit is contained in:
@@ -488,13 +488,29 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
||||
|
||||
{
|
||||
const char *code = (char *)&shared_module[0];
|
||||
if (luaL_loadbuffer(lstate, code, strlen(code), "@shared.lua")
|
||||
if (luaL_loadbuffer(lstate, code, strlen(code), "@vim/shared.lua")
|
||||
|| lua_pcall(lstate, 0, 0, 0)) {
|
||||
nlua_error(lstate, _("E5106: Error while creating shared module: %.*s"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
lua_getglobal(lstate, "package"); // [package]
|
||||
lua_getfield(lstate, -1, "loaded"); // [package, loaded]
|
||||
|
||||
const char *code = (char *)&inspect_module[0];
|
||||
if (luaL_loadbuffer(lstate, code, strlen(code), "@vim/inspect.lua")
|
||||
|| lua_pcall(lstate, 0, 1, 0)) {
|
||||
nlua_error(lstate, _("E5106: Error while creating inspect module: %.*s"));
|
||||
return 1;
|
||||
}
|
||||
// [package, loaded, inspect]
|
||||
|
||||
lua_setfield(lstate, -2, "vim.inspect"); // [package, loaded]
|
||||
lua_pop(lstate, 2); // []
|
||||
}
|
||||
|
||||
{
|
||||
const char *code = (char *)&vim_module[0];
|
||||
if (luaL_loadbuffer(lstate, code, strlen(code), "@vim.lua")
|
||||
|
@@ -36,6 +36,9 @@
|
||||
local vim = vim
|
||||
assert(vim)
|
||||
|
||||
vim.inspect = package.loaded['vim.inspect']
|
||||
assert(vim.inspect)
|
||||
|
||||
-- Internal-only until comments in #8107 are addressed.
|
||||
-- Returns:
|
||||
-- {errcode}, {output}
|
||||
@@ -107,10 +110,6 @@ for s in (package.cpath..';'):gmatch('[^;]*;') do
|
||||
end
|
||||
|
||||
function vim._load_package(name)
|
||||
-- tricky: when debugging this function we must let vim.inspect
|
||||
-- module to be loaded first:
|
||||
--local inspect = (name == "vim.inspect") and tostring or vim.inspect
|
||||
|
||||
local basename = name:gsub('%.', '/')
|
||||
local paths = {"lua/"..basename..".lua", "lua/"..basename.."/init.lua"}
|
||||
for _,path in ipairs(paths) do
|
||||
@@ -260,10 +259,7 @@ end
|
||||
-- These are for loading runtime modules lazily since they aren't available in
|
||||
-- the nvim binary as specified in executor.c
|
||||
local function __index(t, key)
|
||||
if key == 'inspect' then
|
||||
t.inspect = require('vim.inspect')
|
||||
return t.inspect
|
||||
elseif key == 'treesitter' then
|
||||
if key == 'treesitter' then
|
||||
t.treesitter = require('vim.treesitter')
|
||||
return t.treesitter
|
||||
elseif require('vim.uri')[key] ~= nil then
|
||||
|
Reference in New Issue
Block a user