Skip to content

Commit 0ccfe42

Browse files
committed
plugins/cmp/auto-enable: warn if used alongside plugins.*.cmp
1 parent 4f8b10b commit 0ccfe42

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

plugins/cmp/auto-enable.nix

Lines changed: 39 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,46 @@ in
5657
};
5758

5859
config = lib.mkIf (cfg.enable && cfg.autoEnableSources) (
60+
let
61+
enabledCmpPlugins = lib.pipe options.plugins [
62+
# First, a manual blacklist
63+
(lib.flip builtins.removeAttrs [
64+
# lspkind has its own `cmp` options
65+
"lspkind"
66+
])
67+
builtins.attrValues
68+
# Filter for non-options (all plugins are plain attrsets, not options)
69+
# i.e. remove rename aliases
70+
(builtins.filter (opt: !lib.isOption opt))
71+
# Filter for plugins that have `cmp` enabled
72+
(builtins.filter (opt: opt.cmp.value.enable or false))
73+
# Collect the enable options' `loc`s
74+
(builtins.catAttrs "enable")
75+
(builtins.catAttrs "loc")
76+
# Drop the `"enable"` part of the option-loc
77+
(builtins.map (lib.lists.dropEnd 1))
78+
# Render each plugin loc as an option string
79+
(builtins.map lib.showOption)
80+
];
81+
in
5982
lib.mkMerge [
6083
{
6184
warnings = lib.nixvim.mkWarnings "plugins.cmp" [
85+
# Warn when the new and old systems are used together.
86+
# `autoEnableSources` is incompatible with the new `plugins.*.cmp` options
87+
# TODO:
88+
# - Have `autoEnableSources` default to no `plugins.*.cmp` options being enabled?
89+
# - Maybe warn when `autoEnableSources` has highestPrio 1500?
90+
# - I'm not sure how best to migrate to having `plugins.*.cmp.enable` default to true...
91+
{
92+
when = enabledCmpPlugins != [ ];
93+
message = ''
94+
You have enabled `autoEnableSources` that tells Nixvim to automatically enable the source plugins with respect to the list of sources provided in `settings.sources`.
95+
However, ${builtins.toString (builtins.length enabledCmpPlugins)} plugins have cmp integration configured via `plugins.*.cmp`:${
96+
lib.concatMapStrings (opt: "\n- `${opt}`") enabledCmpPlugins
97+
}
98+
'';
99+
}
62100
# TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions
63101
{
64102
when = lib.types.isRawType cfg.settings.sources;
@@ -87,6 +125,7 @@ in
87125
# cmp-foo.enable = true;
88126
# cmp-bar.enable = true;
89127
# }
128+
# NOTE: we use an optionalAttrs here to avoid inf-recursion when `plugins.*.cmp` is used
90129
plugins = lib.mapAttrs' (source: name: {
91130
inherit name;
92131
value.enable = lib.mkIf (lib.elem source enabledSources) true;

0 commit comments

Comments
 (0)