Skip to content

Commit 67e0477

Browse files
committed
plugins/cmp/auto-enable: warn if used alongside plugins.*.cmp
1 parent 1b663b2 commit 67e0477

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

plugins/cmp/auto-enable.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
lib,
33
config,
4+
options,
45
...
56
}:
67
let
@@ -56,9 +57,34 @@ in
5657
};
5758

5859
config = lib.mkIf (cfg.enable && cfg.autoEnableSources) (
60+
let
61+
enabledCmpPlugins = builtins.attrNames (
62+
lib.filterAttrs (_: plugin: plugin.cmp.enable or false) config.plugins
63+
);
64+
enabledCmpPluginOpts = builtins.map (
65+
# Use the plugin's `enable` option to get the full loc with prefix,
66+
# e.g. `programs.nixvim.plugins.foo`
67+
name: lib.showOption (lib.dropEnd 1 options.plugins.${name}.enable.loc)
68+
) enabledCmpPlugins;
69+
in
5970
lib.mkMerge [
6071
{
6172
warnings = lib.nixvim.mkWarnings "plugins.cmp" [
73+
# Warn when the new and old systems are used together.
74+
# `autoEnableSources` is incompatible with the new `plugins.*.cmp` options
75+
# TODO:
76+
# - Have `autoEnableSources` default to no `plugins.*.cmp` options being enabled?
77+
# - Maybe warn when `autoEnableSources` has highestPrio 1500?
78+
# - I'm not sure how best to migrate to having `plugins.*.cmp.enable` default to true...
79+
{
80+
when = enabledCmpPlugins != [ ];
81+
message = ''
82+
You have enabled `autoEnableSources` that tells Nixvim to automatically enable the source plugins with respect to the list of sources provided in `settings.sources`.
83+
However, ${builtins.toString (builtins.length enabledCmpPlugins)} plugins have cmp integration configured via `plugins.*.cmp`:${
84+
lib.concatStringSep (opt: "\n- `${opt}`") enabledCmpPluginOpts
85+
}
86+
'';
87+
}
6288
# TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions
6389
{
6490
when = lib.types.isRawType cfg.settings.sources;

0 commit comments

Comments
 (0)