Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rely on after/plugin for registering sources #2021

Open
2 tasks done
mrcjkb opened this issue Aug 22, 2024 · 2 comments
Open
2 tasks done

Don't rely on after/plugin for registering sources #2021

mrcjkb opened this issue Aug 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mrcjkb
Copy link
Contributor

mrcjkb commented Aug 22, 2024

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

  • 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.

@mrcjkb mrcjkb added the bug Something isn't working label Aug 22, 2024
@mrcjkb
Copy link
Contributor Author

mrcjkb commented Aug 22, 2024

If you're open to the proposed solution, I'd be happy to contribute 😄

@iguanacucumber
Copy link

hi i maintain a fork of nvim-cmp, magazine.nvim, and this looks like something interesting to implement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants