plugins/cmp: refactor source->plugin association

Introduce the internal option `cmpSourcePlugins` where plugins can
register their nvim-cmp source name association.
This commit is contained in:
Matt Sturgeon 2024-06-29 08:26:56 +01:00
parent bd422db9ba
commit 3a8d4fee35
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
6 changed files with 137 additions and 100 deletions

View file

@ -16,42 +16,22 @@ helpers.neovim-plugin.mkNeovimPlugin config {
maintainers = [ maintainers.GaetanLepage ];
# Introduced on 2024 February 21
# TODO: remove ~June 2024
imports = [
# Introduced on 2024 February 21
# TODO: remove ~June 2024
./deprecations.nix
./auto-enable.nix
./sources
];
deprecateExtraOptions = true;
inherit (cmpOptions) settingsOptions settingsExample;
extraOptions = {
autoEnableSources = mkOption {
type = types.bool;
default = true;
description = ''
Scans the sources array and installs the plugins if they are known to nixvim.
'';
};
inherit (cmpOptions) filetype cmdline;
};
inherit (cmpOptions) settingsOptions settingsExample;
callSetup = false;
extraConfig = cfg: {
warnings =
optional (cfg.autoEnableSources && (helpers.nixvimTypes.isRawType cfg.settings.sources))
''
Nixvim (plugins.cmp): You have enabled `autoEnableSources` that tells Nixvim to automatically
enable the source plugins with respect to the list of sources provided in `settings.sources`.
However, the latter is proveded as a raw lua string which is not parseable by Nixvim.
If you want to keep using raw lua for defining your sources:
- Ensure you enable the relevant plugins manually in your configuration;
- Dismiss this warning by explicitly setting `autoEnableSources` to `false`;
'';
extraConfigLua =
''
local cmp = require('cmp')
@ -68,9 +48,5 @@ helpers.neovim-plugin.mkNeovimPlugin config {
cmdtype: settings: "cmp.setup.cmdline('${cmdtype}', ${helpers.toLuaObject settings})\n"
) cfg.cmdline
));
# If autoEnableSources is set to true, figure out which are provided by the user
# and enable the corresponding plugins.
plugins = (import ./cmp-helpers.nix args).autoInstallSourcePluginsModule cfg;
};
}