neovim/neovim

Lua: search 'packpath' from require() without :packloadall

justinmk opened this issue · 2 comments

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')
.

:packloadall ignores redundant calls, so it might be ok to do it implicitly on require(). But maybe this is too magic?

Discussion

  1. 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
    • So we don't want Lua require() to trigger implicit :packloadall.
  2. Q: Why doesn't require('foo') find something in pack/…/start/foo/lua, without sourcing plugin/foo.vim ?
    • A: Presumably this is "unexpected" in some cases.
  3. 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.

I think this is fixed as of #13119 merging.

Indeed