Lua: search 'packpath' from require() without :packloadall
justinmk opened this issue · 2 comments
justinmk commented
If a Lua plugin like https://github.com/neovim/nvim-lspconfig is installed in the vim 'packpath' as a /start/
package , its Lua modules are not available from vimrc (init.vim) during startup:
lua <<
require('foo')
.
Adding :packloadall
before that code makes the module available.
packloadall
lua <<
require('foo')
.
But maybe this is too magic?:packloadall
ignores redundant calls, so it might be ok to do it implicitly on require()
.
Discussion
- Q: why :packloadall is not done before vimrc ? This means stuff in /start/ is not available for use in vimrc...
- A: Same reason that nothing else in 'runtimepath' is loaded before vimrc:
- to avoid sourcing
plugin/*
- to allow the vimrc to customize what happens
- to avoid sourcing
- So we don't want Lua
require()
to trigger implicit:packloadall
.
- A: Same reason that nothing else in 'runtimepath' is loaded before vimrc:
- Q: Why doesn't
require('foo')
find something inpack/…/start/foo/lua
, without sourcingplugin/foo.vim
?- A: Presumably this is "unexpected" in some cases.
- Q: why
:packloadall
insists on actually sourcing the plugins, rather than simply being the mechanism to say "I've updated 'packpath', please make 'runtimepath' reflect that"? That's the main capability that should be desired at startup. In your vimrc, you want to be able to potentially adjust 'packpath', get that reflected in 'runtimepath', and then you'll have access to autoload-type things (like Lua) and can do the normal configuration one would expect.
Plan
Do (2). But for that to work, we need a mechanism to achieve (3): something that updates 'runtimepath' without also sourcing plugin/*
stuff.
kamalmarhubi commented
I think this is fixed as of #13119 merging.
bfredl commented
Indeed