mirror of
https://github.com/neovim/neovim
synced 2025-07-18 02:01:46 +00:00
fix(lua): remove vim.loader.disable() #31344
Problem:
`vim.loader.disable` does not conform to `:help dev-name-common` and
`:help dev-patterns`.
Solution:
- Add `enable` parameter to `vim.loader.enable`
- Remove `vim.loader.disable`
- Note the change in `:help news-breaking-dev` (HEAD changes).
- This is not a breaking change (except to "HEAD") because
`vim.loader` is marked "experimental".
previous: 26765e8461
This commit is contained in:
@ -2485,22 +2485,24 @@ vim.validate({name}, {value}, {validator}, {optional}, {message})
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
Lua module: vim.loader *vim.loader*
|
Lua module: vim.loader *vim.loader*
|
||||||
|
|
||||||
vim.loader.disable() *vim.loader.disable()*
|
vim.loader.enable({enable}) *vim.loader.enable()*
|
||||||
WARNING: This feature is experimental/unstable.
|
WARNING: This feature is experimental/unstable.
|
||||||
|
|
||||||
Disables the experimental Lua module loader:
|
Enables or disables the experimental Lua module loader:
|
||||||
• removes the loaders
|
|
||||||
• adds the default Nvim loader
|
|
||||||
|
|
||||||
vim.loader.enable() *vim.loader.enable()*
|
Enable (`enable=true`):
|
||||||
WARNING: This feature is experimental/unstable.
|
• overrides |loadfile()|
|
||||||
|
|
||||||
Enables the experimental Lua module loader:
|
|
||||||
• overrides loadfile
|
|
||||||
• adds the Lua loader using the byte-compilation cache
|
• adds the Lua loader using the byte-compilation cache
|
||||||
• adds the libs loader
|
• adds the libs loader
|
||||||
• removes the default Nvim loader
|
• removes the default Nvim loader
|
||||||
|
|
||||||
|
Disable (`enable=false`):
|
||||||
|
• removes the loaders
|
||||||
|
• adds the default Nvim loader
|
||||||
|
|
||||||
|
Parameters: ~
|
||||||
|
• {enable} (`boolean?`) true/nil to enable, false to disable
|
||||||
|
|
||||||
vim.loader.find({modname}, {opts}) *vim.loader.find()*
|
vim.loader.find({modname}, {opts}) *vim.loader.find()*
|
||||||
WARNING: This feature is experimental/unstable.
|
WARNING: This feature is experimental/unstable.
|
||||||
|
|
||||||
|
@ -11,13 +11,17 @@ For changes in the previous release, see |news-0.10|.
|
|||||||
Type |gO| to see the table of contents.
|
Type |gO| to see the table of contents.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
BREAKING CHANGES IN HEAD *news-breaking-dev*
|
BREAKING CHANGES IN HEAD OR EXPERIMENTAL *news-breaking-dev*
|
||||||
|
|
||||||
====== Remove this section before release. ======
|
====== Remove this section before release. ======
|
||||||
|
|
||||||
The following changes to UNRELEASED features were made during the development
|
The following changes to UNRELEASED features were made during the development
|
||||||
cycle (Nvim HEAD, the "master" branch).
|
cycle (Nvim HEAD, the "master" branch).
|
||||||
|
|
||||||
|
EXPERIMENTS
|
||||||
|
|
||||||
|
• Removed `vim.loader.disable()`. Use `vim.loader.enable(false)` instead.
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
|
|
||||||
• 'jumpoptions' flag "unload" has been renamed to "clean".
|
• 'jumpoptions' flag "unload" has been renamed to "clean".
|
||||||
|
@ -399,18 +399,29 @@ function M.reset(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Enables the experimental Lua module loader:
|
--- Enables or disables the experimental Lua module loader:
|
||||||
--- * overrides loadfile
|
---
|
||||||
|
--- Enable (`enable=true`):
|
||||||
|
--- * overrides |loadfile()|
|
||||||
--- * adds the Lua loader using the byte-compilation cache
|
--- * adds the Lua loader using the byte-compilation cache
|
||||||
--- * adds the libs loader
|
--- * adds the libs loader
|
||||||
--- * removes the default Nvim loader
|
--- * removes the default Nvim loader
|
||||||
---
|
---
|
||||||
|
--- Disable (`enable=false`):
|
||||||
|
--- * removes the loaders
|
||||||
|
--- * adds the default Nvim loader
|
||||||
|
---
|
||||||
--- @since 0
|
--- @since 0
|
||||||
function M.enable()
|
---
|
||||||
if M.enabled then
|
--- @param enable? (boolean) true/nil to enable, false to disable
|
||||||
|
function M.enable(enable)
|
||||||
|
enable = enable == nil and true or enable
|
||||||
|
if enable == M.enabled then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
M.enabled = true
|
M.enabled = enable
|
||||||
|
|
||||||
|
if enable then
|
||||||
vim.fn.mkdir(vim.fn.fnamemodify(M.path, ':p'), 'p')
|
vim.fn.mkdir(vim.fn.fnamemodify(M.path, ':p'), 'p')
|
||||||
_G.loadfile = loadfile_cached
|
_G.loadfile = loadfile_cached
|
||||||
-- add Lua loader
|
-- add Lua loader
|
||||||
@ -424,18 +435,7 @@ function M.enable()
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
|
||||||
--- Disables the experimental Lua module loader:
|
|
||||||
--- * removes the loaders
|
|
||||||
--- * adds the default Nvim loader
|
|
||||||
---
|
|
||||||
--- @since 0
|
|
||||||
function M.disable()
|
|
||||||
if not M.enabled then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
M.enabled = false
|
|
||||||
_G.loadfile = _loadfile
|
_G.loadfile = _loadfile
|
||||||
for l, loader in ipairs(loaders) do
|
for l, loader in ipairs(loaders) do
|
||||||
if loader == loader_cached or loader == loader_lib_cached then
|
if loader == loader_cached or loader == loader_lib_cached then
|
||||||
@ -443,6 +443,7 @@ function M.disable()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(loaders, 2, vim._load_package)
|
table.insert(loaders, 2, vim._load_package)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Tracks the time spent in a function
|
--- Tracks the time spent in a function
|
||||||
|
@ -10,7 +10,17 @@ local eq = t.eq
|
|||||||
describe('vim.loader', function()
|
describe('vim.loader', function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
it('can work in compatibility with --luamod-dev #27413', function()
|
it('can be disabled', function()
|
||||||
|
exec_lua(function()
|
||||||
|
local orig_loader = _G.loadfile
|
||||||
|
vim.loader.enable()
|
||||||
|
assert(orig_loader ~= _G.loadfile)
|
||||||
|
vim.loader.enable(false)
|
||||||
|
assert(orig_loader == _G.loadfile)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('works with --luamod-dev #27413', function()
|
||||||
clear({ args = { '--luamod-dev' } })
|
clear({ args = { '--luamod-dev' } })
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
@ -31,7 +41,7 @@ describe('vim.loader', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('handles changing files (#23027)', function()
|
it('handles changing files #23027', function()
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
end)
|
end)
|
||||||
@ -63,7 +73,7 @@ describe('vim.loader', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('handles % signs in modpath (#24491)', function()
|
it('handles % signs in modpath #24491', function()
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
]]
|
]]
|
||||||
@ -82,7 +92,7 @@ describe('vim.loader', function()
|
|||||||
eq(2, exec_lua('return loadfile(...)()', tmp2))
|
eq(2, exec_lua('return loadfile(...)()', tmp2))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('correct indent on error message (#29809)', function()
|
it('indents error message #29809', function()
|
||||||
local errmsg = exec_lua [[
|
local errmsg = exec_lua [[
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
local _, errmsg = pcall(require, 'non_existent_module')
|
local _, errmsg = pcall(require, 'non_existent_module')
|
||||||
|
Reference in New Issue
Block a user