mirror of
https://github.com/neovim/neovim.git
synced 2025-12-11 17:12:40 +00:00
fix(pack)!: make default opts.load in add() to work inside 'plugin/'
Problem: Plain `vim.pack.add()` calls (with default `opts.load`) does not fully work if called inside 'plugin/' runtime directory. In particular, 'plugin/' files of newly added plugins are not sourced. This is because `opts.load` is `false` during the whole startup, which means `:packadd!` is used (modify 'runtimepath' but not force source newly added 'plugin/' files). This use case is common due to users organizing their config as separate files in '~/.config/nvim/plugin/'. Solution: Use newly added `v:vim_did_init` to decide default `opts.load` value instead of `v:vim_did_enter`.
This commit is contained in:
@@ -620,35 +620,42 @@ describe('vim.pack', function()
|
||||
end)
|
||||
|
||||
describe('startup', function()
|
||||
local init_lua = ''
|
||||
local config_dir, pack_add_cmd = '', ''
|
||||
|
||||
before_each(function()
|
||||
init_lua = vim.fs.joinpath(fn.stdpath('config'), 'init.lua')
|
||||
fn.mkdir(vim.fs.dirname(init_lua), 'p')
|
||||
config_dir = fn.stdpath('config')
|
||||
fn.mkdir(vim.fs.joinpath(config_dir, 'plugin'), 'p')
|
||||
|
||||
pack_add_cmd = ('vim.pack.add({ %s })'):format(vim.inspect(repos_src.plugindirs))
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
pcall(vim.fs.rm, init_lua, { force = true })
|
||||
vim.fs.rm(config_dir, { recursive = true, force = true })
|
||||
end)
|
||||
|
||||
it('works in init.lua', function()
|
||||
local pack_add_cmd = ('vim.pack.add({ %s })'):format(vim.inspect(repos_src.plugindirs))
|
||||
fn.writefile({ pack_add_cmd, '_G.done = true' }, init_lua)
|
||||
local function assert_loaded()
|
||||
eq('plugindirs main', exec_lua('return require("plugindirs")'))
|
||||
|
||||
local function assert_loaded()
|
||||
eq('plugindirs main', exec_lua('return require("plugindirs")'))
|
||||
|
||||
-- Should source 'plugin/' and 'after/plugin/' exactly once
|
||||
eq({ true, true }, n.exec_lua('return { vim.g._plugin, vim.g._after_plugin }'))
|
||||
eq({ 'p', 'a' }, n.exec_lua('return _G.DL'))
|
||||
end
|
||||
-- Should source 'plugin/' and 'after/plugin/' exactly once
|
||||
eq({ true, true }, n.exec_lua('return { vim.g._plugin, vim.g._after_plugin }'))
|
||||
eq({ 'p', 'a' }, n.exec_lua('return _G.DL'))
|
||||
end
|
||||
|
||||
local function assert_works()
|
||||
-- Should auto-install but wait before executing code after it
|
||||
n.clear({ args_rm = { '-u' } })
|
||||
n.exec_lua('vim.wait(500, function() return _G.done end, 50)')
|
||||
assert_loaded()
|
||||
|
||||
-- Should only `:packadd!` already installed plugin
|
||||
-- Should only `:packadd!`/`:packadd` already installed plugin
|
||||
n.clear({ args_rm = { '-u' } })
|
||||
assert_loaded()
|
||||
end
|
||||
|
||||
it('works in init.lua', function()
|
||||
local init_lua = vim.fs.joinpath(config_dir, 'init.lua')
|
||||
fn.writefile({ pack_add_cmd, '_G.done = true' }, init_lua)
|
||||
assert_works()
|
||||
|
||||
-- Should not load plugins if `--noplugin`, only adjust 'runtimepath'
|
||||
n.clear({ args = { '--noplugin' }, args_rm = { '-u' } })
|
||||
@@ -656,6 +663,13 @@ describe('vim.pack', function()
|
||||
eq({}, n.exec_lua('return { vim.g._plugin, vim.g._after_plugin }'))
|
||||
eq(vim.NIL, n.exec_lua('return _G.DL'))
|
||||
end)
|
||||
|
||||
it('works in plugin/', function()
|
||||
local plugin_file = vim.fs.joinpath(config_dir, 'plugin', 'mine.lua')
|
||||
fn.writefile({ pack_add_cmd, '_G.done = true' }, plugin_file)
|
||||
-- Should source plugin's 'plugin/' files without explicit `load=true`
|
||||
assert_works()
|
||||
end)
|
||||
end)
|
||||
|
||||
it('shows progress report during installation', function()
|
||||
|
||||
Reference in New Issue
Block a user