mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #17621 from bfredl/luaindex
refactor(lua): make vim submodule lazy loading declarative
This commit is contained in:
commit
c3cc17f0e6
@ -3,9 +3,11 @@
|
|||||||
-- Lua code lives in one of three places:
|
-- Lua code lives in one of three places:
|
||||||
-- 1. runtime/lua/vim/ (the runtime): For "nice to have" features, e.g. the
|
-- 1. runtime/lua/vim/ (the runtime): For "nice to have" features, e.g. the
|
||||||
-- `inspect` and `lpeg` modules.
|
-- `inspect` and `lpeg` modules.
|
||||||
-- 2. runtime/lua/vim/shared.lua: Code shared between Nvim and tests.
|
-- 2. runtime/lua/vim/shared.lua: pure lua functions which always
|
||||||
-- (This will go away if we migrate to nvim as the test-runner.)
|
-- are available. Used in the test runner, as well as worker threads
|
||||||
-- 3. runtime/lua/vim/_editor.lua: Compiled-into Nvim itself.
|
-- and processes launched from Nvim.
|
||||||
|
-- 3. runtime/lua/vim/_editor.lua: Code which directly interacts with
|
||||||
|
-- the Nvim editor state. Only available in the main thread.
|
||||||
--
|
--
|
||||||
-- Guideline: "If in doubt, put it in the runtime".
|
-- Guideline: "If in doubt, put it in the runtime".
|
||||||
--
|
--
|
||||||
@ -35,43 +37,19 @@
|
|||||||
-- - https://github.com/howl-editor/howl/tree/master/lib/howl/util
|
-- - https://github.com/howl-editor/howl/tree/master/lib/howl/util
|
||||||
|
|
||||||
local vim = assert(vim)
|
local vim = assert(vim)
|
||||||
assert(vim.inspect)
|
|
||||||
|
|
||||||
-- These are for loading runtime modules lazily since they aren't available in
|
-- These are for loading runtime modules lazily since they aren't available in
|
||||||
-- the nvim binary as specified in executor.c
|
-- the nvim binary as specified in executor.c
|
||||||
setmetatable(vim, {
|
for k,v in pairs {
|
||||||
__index = function(t, key)
|
treesitter=true;
|
||||||
if key == 'treesitter' then
|
filetype = true;
|
||||||
t.treesitter = require('vim.treesitter')
|
F=true;
|
||||||
return t.treesitter
|
lsp=true;
|
||||||
elseif key == 'filetype' then
|
highlight=true;
|
||||||
t.filetype = require('vim.filetype')
|
diagnostic=true;
|
||||||
return t.filetype
|
keymap=true;
|
||||||
elseif key == 'F' then
|
ui=true;
|
||||||
t.F = require('vim.F')
|
} do vim._submodules[k] = v end
|
||||||
return t.F
|
|
||||||
elseif require('vim.uri')[key] ~= nil then
|
|
||||||
-- Expose all `vim.uri` functions on the `vim` module.
|
|
||||||
t[key] = require('vim.uri')[key]
|
|
||||||
return t[key]
|
|
||||||
elseif key == 'lsp' then
|
|
||||||
t.lsp = require('vim.lsp')
|
|
||||||
return t.lsp
|
|
||||||
elseif key == 'highlight' then
|
|
||||||
t.highlight = require('vim.highlight')
|
|
||||||
return t.highlight
|
|
||||||
elseif key == 'diagnostic' then
|
|
||||||
t.diagnostic = require('vim.diagnostic')
|
|
||||||
return t.diagnostic
|
|
||||||
elseif key == 'keymap' then
|
|
||||||
t.keymap = require('vim.keymap')
|
|
||||||
return t.keymap
|
|
||||||
elseif key == 'ui' then
|
|
||||||
t.ui = require('vim.ui')
|
|
||||||
return t.ui
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.log = {
|
vim.log = {
|
||||||
levels = {
|
levels = {
|
||||||
|
@ -50,7 +50,25 @@ table.insert(package.loaders, 2, vim._load_package)
|
|||||||
|
|
||||||
-- builtin functions which always should be available
|
-- builtin functions which always should be available
|
||||||
require'vim.shared'
|
require'vim.shared'
|
||||||
vim.inspect = require'vim.inspect'
|
|
||||||
|
vim._submodules = {inspect=true}
|
||||||
|
|
||||||
|
-- These are for loading runtime modules in the vim namespace lazily.
|
||||||
|
setmetatable(vim, {
|
||||||
|
__index = function(t, key)
|
||||||
|
if vim._submodules[key] then
|
||||||
|
t[key] = require('vim.'..key)
|
||||||
|
return t[key]
|
||||||
|
elseif vim.startswith(key, 'uri_') then
|
||||||
|
local val = require('vim.uri')[key]
|
||||||
|
if val ~= nil then
|
||||||
|
-- Expose all `vim.uri` functions on the `vim` module.
|
||||||
|
t[key] = val
|
||||||
|
return t[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
--- <Docs described in |vim.empty_dict()| >
|
--- <Docs described in |vim.empty_dict()| >
|
||||||
---@private
|
---@private
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
-- Functions shared by Nvim and its test-suite.
|
-- Functions shared by Nvim and its test-suite.
|
||||||
--
|
--
|
||||||
-- The singular purpose of this module is to share code with the Nvim
|
-- These are "pure" lua functions not depending of the state of the editor.
|
||||||
-- test-suite. If, in the future, Nvim itself is used to run the test-suite
|
-- Thus they should always be available whenever nvim-related lua code is run,
|
||||||
-- instead of "vanilla Lua", these functions could move to runtime/lua/vim/_editor.lua
|
-- regardless if it is code in the editor itself, or in worker threads/processes,
|
||||||
|
-- or the test suite. (Eventually the test suite will be run in a worker process,
|
||||||
|
-- so this wouldn't be a separate case to consider)
|
||||||
|
|
||||||
local vim = vim or {}
|
local vim = vim or {}
|
||||||
|
|
||||||
|
@ -342,6 +342,7 @@ add_custom_command(
|
|||||||
${LUA_KEYMAP_MODULE_SOURCE} "vim.keymap"
|
${LUA_KEYMAP_MODULE_SOURCE} "vim.keymap"
|
||||||
DEPENDS
|
DEPENDS
|
||||||
${CHAR_BLOB_GENERATOR}
|
${CHAR_BLOB_GENERATOR}
|
||||||
|
${LUA_INIT_PACKAGES_MODULE_SOURCE}
|
||||||
${LUA_EDITOR_MODULE_SOURCE}
|
${LUA_EDITOR_MODULE_SOURCE}
|
||||||
${LUA_SHARED_MODULE_SOURCE}
|
${LUA_SHARED_MODULE_SOURCE}
|
||||||
${LUA_INSPECT_MODULE_SOURCE}
|
${LUA_INSPECT_MODULE_SOURCE}
|
||||||
|
Loading…
Reference in New Issue
Block a user