You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nvim-cmp and a completion source (e.g. cmp-nvim-lsp) installed as opt plugins in the packpath
packadd nvim-cmp and cmp-nvim-lsp within an autocommand (e.g. InsertEnter).
Description
Most completion sources rely on after/plugin to register themselves, and the impact on startup time can be quite heavy (especially when a lot of sources are installed).
For this reason, it can be desirable to install the plugins as opt plugins and lazy-load them (e.g. on an InsertEnter event).
But nvim-cmp sources rely on after/plugin to register themselves (for lack of an API).
Because Neovim doesn't source after scripts once the startup initialisation has completed, the sources won't register themselves and nvim-cmp will error when trying to pass them in via the setup function.
Steps to reproduce
Install nvim-cmp and cmp-nvim-lsp to opt
Create an autocommand for InsertEnter with a callback that
packadd! nvim-cmp
packadd cmp-nvim-lsp
calls cmp.setup to add the source.
packadd nvim-cmp
Expected behavior
No error. nvim-cmp and the LSP source configured and loaded on InsertEnter
Actual behavior
nvim-cmp errors when calling setup, due to the missing source.
Additional context
A potential solution would be to execute a :h User autocommand with the pattern CmpRegisterSourcePre at the start of the setup call, or in the main module that loads the setup function.
Sources could create an autocommand with that pattern to ensure they are registered at the appropriate time.
The text was updated successfully, but these errors were encountered:
FAQ
Announcement
Minimal reproducible full config
opt
plugins in the packpathpackadd
nvim-cmp and cmp-nvim-lsp within an autocommand (e.g.InsertEnter
).Description
Most completion sources rely on
after/plugin
to register themselves, and the impact on startup time can be quite heavy (especially when a lot of sources are installed).For this reason, it can be desirable to install the plugins as
opt
plugins and lazy-load them (e.g. on anInsertEnter
event).But nvim-cmp sources rely on
after/plugin
to register themselves (for lack of an API).Because Neovim doesn't source
after
scripts once the startup initialisation has completed, the sources won't register themselves and nvim-cmp will error when trying to pass them in via thesetup
function.Steps to reproduce
opt
InsertEnter
with a callback thatpackadd! nvim-cmp
packadd cmp-nvim-lsp
cmp.setup
to add the source.packadd nvim-cmp
Expected behavior
No error. nvim-cmp and the LSP source configured and loaded on
InsertEnter
Actual behavior
nvim-cmp errors when calling
setup
, due to the missing source.Additional context
A potential solution would be to execute a
:h User
autocommand with the patternCmpRegisterSourcePre
at the start of thesetup
call, or in the main module that loads thesetup
function.Sources could create an autocommand with that pattern to ensure they are registered at the appropriate time.
The text was updated successfully, but these errors were encountered: