Skip to content

Commit aa4b060

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

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

plugins/cmp/auto-enable.nix

Lines changed: 38 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+
62+
enabledCmpPlugins = lib.pipe options.plugins [
63+
# First, a manual blacklist
64+
(lib.flip builtins.removeAttrs [
65+
# lspkind has its own `cmp` options
66+
"lspkind"
67+
])
68+
# Filter for non-options (all plugins are plain attrsets, not options)
69+
# i.e. remove rename aliases
70+
(lib.filterAttrs (name: opt: !lib.isOption opt))
71+
# Filter for plugins that have `cmp` enabled
72+
(lib.filterAttrs (name: _: config.plugins.${name}.cmp.enable or false))
73+
# Collect the enable options' `loc`s
74+
(lib.mapAttrsToList (_: plugin: plugin.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;

0 commit comments

Comments
 (0)