Skip to content

Commit d3beeeb

Browse files
committed
plugins/cmp/auto-enable: remove cmpSourcePlugins option
This is no longer used, thanks to the new `mkCmpPluginModule` impl.
1 parent fd3b669 commit d3beeeb

File tree

4 files changed

+77
-105
lines changed

4 files changed

+77
-105
lines changed

lib/modules.nix

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -315,33 +315,24 @@ in
315315
};
316316
};
317317
};
318-
config = lib.mkMerge [
319-
{
320-
# Backwards compatibility with autoEnableCmpSources
321-
cmpSourcePlugins.${sourceName} =
322-
assert lib.assertMsg (builtins.length loc == 2 && builtins.head loc == "plugins")
323-
"autoEnableCmpSources assumes all cmp source plugins are in the `plugins` namespace. Unsupported plugin `${lib.showOption loc}`.";
324-
pluginName;
325-
}
326-
(lib.mkIf (pluginCfg.enable && cfg.enable) {
327-
# FIXME: even though we have the mkIf, we also need optionalAttrs
328-
# to avoid inf-recursion caused by `autoEnableSources`
329-
plugins.cmp = lib.optionalAttrs cfg.enable {
330-
# TODO: consider setting:
331-
# autoEnableSources = lib.mkDefault false;
332-
settings = lib.mkIf (cfg.default != false) (toSources cfg.default);
333-
cmdline = lib.mkIf (cfg.cmdline != { }) (builtins.mapAttrs (_: toSources) cfg.cmdline);
334-
filetype = lib.mkIf (cfg.filetypes != { }) (builtins.mapAttrs (_: toSources) cfg.filetypes);
335-
};
336-
warnings = lib.nixvim.mkWarnings (lib.showOption loc) {
337-
when = !config.plugins.cmp.enable && options.plugins.cmp.enable.highestPrio == 1500;
338-
message = ''
339-
You have enabled the nvim-cmp source, but `plugins.cmp` is not enabled.
340-
You can disable this warning by explicitly setting `plugins.cmp.enable = false`.
341-
'';
342-
};
343-
})
344-
];
318+
config = lib.mkIf (pluginCfg.enable && cfg.enable) {
319+
# FIXME: even though we have the mkIf, we also need optionalAttrs
320+
# to avoid inf-recursion caused by `autoEnableSources`
321+
plugins.cmp = lib.optionalAttrs cfg.enable {
322+
# TODO: consider setting:
323+
# autoEnableSources = lib.mkDefault false;
324+
settings = lib.mkIf (cfg.default != false) (toSources cfg.default);
325+
cmdline = lib.mkIf (cfg.cmdline != { }) (builtins.mapAttrs (_: toSources) cfg.cmdline);
326+
filetype = lib.mkIf (cfg.filetypes != { }) (builtins.mapAttrs (_: toSources) cfg.filetypes);
327+
};
328+
warnings = lib.nixvim.mkWarnings (lib.showOption loc) {
329+
when = !config.plugins.cmp.enable && options.plugins.cmp.enable.highestPrio == 1500;
330+
message = ''
331+
You have enabled the nvim-cmp source, but `plugins.cmp` is not enabled.
332+
You can disable this warning by explicitly setting `plugins.cmp.enable = false`.
333+
'';
334+
};
335+
};
345336
};
346337
}
347338
// lib.mapAttrs (

plugins/by-name/otter/default.nix

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ lib.nixvim.plugins.mkNeovimPlugin {
2525
> If you previously used the otter nvim-cmp source, you can remove it, as the completion results now come directly via the cmp-nvim-lsp source together with other language servers.
2626
''
2727
)
28-
29-
# Register nvim-cmp association
30-
# TODO: Otter is no longer a cmp-source
31-
# Deprecated 2024-09-22; remove after 24.11
32-
# Note: a warning is implemented in plugins/cmp/auto-enable.nix
33-
{ cmpSourcePlugins.otter = "otter"; }
3428
];
3529

3630
settingsOptions = {

plugins/cmp/auto-enable.nix

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,12 @@ let
4949
];
5050
in
5151
{
52+
imports = [
53+
(lib.mkRemovedOptionModule [
54+
"cmpSourcePlugins"
55+
] "Use `lib.nixvim.modules.mkCmpPluginModule` instead.")
56+
];
5257
options = {
53-
# Note: this option must be outside of `plugins` to avoid infinite recursion
54-
cmpSourcePlugins = lib.mkOption {
55-
type = with lib.types; attrsOf str;
56-
default = { };
57-
description = ''
58-
Internal option used to associate nvim-cmp source names with nixvim plugin module names.
59-
60-
Maps `<source-name> = <plugin-name>` where _plugin-name_ is the module name: `plugins.<plugin-name>.enable`.
61-
'';
62-
example = {
63-
foo = "cmp-foo";
64-
bar = "cmp-bar";
65-
};
66-
internal = true;
67-
visible = false;
68-
};
69-
7058
plugins.cmp.autoEnableSources = lib.mkOption {
7159
type = lib.types.bool;
7260
default = true;

tests/test-sources/plugins/cmp/all-sources.nix

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
{ pkgs, ... }:
2+
let
3+
# TODO: move into the relevant module once we only have one "all" test
4+
disabledSources =
5+
[
6+
# We do not provide the required HF_API_KEY environment variable.
7+
"cmp-ai"
8+
# Triggers the warning complaining about treesitter highlighting being disabled
9+
"otter"
10+
# Invokes the `nix` command at startup which is not available in the sandbox
11+
"cmp-nixpkgs-maintainers"
12+
# lspkind has its own `cmp` options, but isn't a nvim-cmp source
13+
"lspkind"
14+
]
15+
# TODO: why is this disabled?
16+
++ pkgs.lib.optionals (pkgs.stdenv.hostPlatform.system == "aarch64-linux") [
17+
"cmp-tabnine"
18+
];
19+
in
220
{
321
all-sources =
422
{
523
config,
624
options,
725
lib,
8-
pkgs,
926
...
1027
}:
1128
{
@@ -26,45 +43,32 @@
2643
};
2744
}
2845
{
29-
plugins =
30-
let
31-
disabledSources =
32-
[
33-
# We do not provide the required HF_API_KEY environment variable.
34-
"cmp-ai"
35-
# Triggers the warning complaining about treesitter highlighting being disabled
36-
"otter"
37-
# Invokes the `nix` command at startup which is not available in the sandbox
38-
"cmp-nixpkgs-maintainers"
39-
# lspkind has its own `cmp` options, but isn't a nvim-cmp source
40-
"lspkind"
41-
]
42-
# TODO: why is this disabled?
43-
++ lib.optionals (pkgs.stdenv.hostPlatform.system == "aarch64-linux") [
44-
"cmp-tabnine"
45-
];
46-
cmpPluginNames = lib.pipe options.plugins [
47-
# First, a manual blacklist
48-
(lib.flip builtins.removeAttrs disabledSources)
49-
# Filter for non-options (all plugins are plain attrsets, not options)
50-
# i.e. remove rename aliases
51-
(lib.filterAttrs (name: opt: !lib.isOption opt))
52-
# Collect the plugin names
53-
builtins.attrNames
54-
# Filter for plugins that have a `cmp` option
55-
(builtins.filter (name: config.plugins.${name} ? cmp))
56-
];
57-
in
58-
lib.genAttrs cmpPluginNames (name: {
46+
plugins = lib.pipe options.plugins [
47+
# First, a manual blacklist
48+
(lib.flip builtins.removeAttrs disabledSources)
49+
# Filter for non-options (all plugins are plain attrsets, not options)
50+
# i.e. remove rename aliases
51+
(lib.filterAttrs (name: opt: !lib.isOption opt))
52+
# Collect the plugin names
53+
builtins.attrNames
54+
# Filter for plugins that have a `cmp` option
55+
(builtins.filter (name: config.plugins.${name} ? cmp))
56+
(lib.flip lib.genAttrs (name: {
5957
enable = true;
6058
cmp.enable = true;
61-
});
59+
}))
60+
];
6261
}
6362
];
6463
};
6564

6665
auto-enable-sources =
67-
{ config, ... }:
66+
{
67+
config,
68+
options,
69+
lib,
70+
...
71+
}:
6872
{
6973
plugins = {
7074
copilot-lua = {
@@ -78,28 +82,23 @@
7882

7983
cmp = {
8084
enable = true;
81-
settings.sources =
82-
with pkgs.lib;
83-
let
84-
disabledSources = [
85-
# We do not provide the required HF_API_KEY environment variable.
86-
"cmp_ai"
87-
# Triggers the warning complaining about treesitter highlighting being disabled
88-
"otter"
89-
# Invokes the `nix` command at startup which is not available in the sandbox
90-
"nixpkgs_maintainers"
91-
] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine";
92-
in
93-
pipe config.cmpSourcePlugins [
94-
# All known source names
95-
attrNames
96-
# Filter out disabled sources
97-
(filter (name: !(elem name disabledSources)))
98-
# Convert names to source attributes
99-
(map (name: {
100-
inherit name;
101-
}))
102-
];
85+
settings.sources = lib.pipe options.plugins [
86+
# First, a manual blacklist
87+
(lib.flip builtins.removeAttrs disabledSources)
88+
# Filter for non-options (all plugins are plain attrsets, not options)
89+
# i.e. remove rename aliases
90+
(lib.filterAttrs (name: opt: !lib.isOption opt))
91+
# Collect the plugin names
92+
builtins.attrNames
93+
# Filter for plugins that have a `cmp` option
94+
(builtins.filter (name: config.plugins.${name} ? cmp))
95+
# Map to the source name
96+
(builtins.map (name: config.plugins.${name}.cmp.name))
97+
# Map to a plugin definition
98+
(builtins.map (name: {
99+
inherit name;
100+
}))
101+
];
103102
};
104103
};
105104
};

0 commit comments

Comments
 (0)