plugins/cmp: remove with lib;

This commit is contained in:
Austin Horstman 2024-10-06 09:57:31 -05:00
parent d71cfaaae8
commit 62b87e5b56
No known key found for this signature in database
13 changed files with 92 additions and 92 deletions

View file

@ -1,38 +1,36 @@
{ {
lib, lib,
helpers,
config, config,
... ...
}: }:
with lib;
let let
cfg = config.plugins.cmp; cfg = config.plugins.cmp;
extractSources = { sources, ... }: if isList sources then sources else [ ]; extractSources = { sources, ... }: if lib.isList sources then sources else [ ];
# Collect the names of the sources provided by the user # Collect the names of the sources provided by the user
# ["foo" "bar"] # ["foo" "bar"]
enabledSources = enabledSources =
pipe lib.pipe
[ [
# cfg.setup.sources # cfg.setup.sources
(extractSources cfg.settings) (extractSources cfg.settings)
# cfg.filetype.<name>.sources # cfg.filetype.<name>.sources
(mapAttrsToList (_: extractSources) cfg.filetype) (lib.mapAttrsToList (_: extractSources) cfg.filetype)
# cfg.cmdline.<name>.sources # cfg.cmdline.<name>.sources
(mapAttrsToList (_: extractSources) cfg.cmdline) (lib.mapAttrsToList (_: extractSources) cfg.cmdline)
] ]
[ [
flatten lib.flatten
(map (getAttr "name")) (map (lib.getAttr "name"))
unique lib.unique
]; ];
in in
{ {
options = { options = {
# Note: this option must be outside of `plugins` to avoid infinite recursion # Note: this option must be outside of `plugins` to avoid infinite recursion
cmpSourcePlugins = mkOption { cmpSourcePlugins = lib.mkOption {
type = with types; attrsOf str; type = with lib.types; attrsOf str;
default = { }; default = { };
description = '' description = ''
Internal option used to associate nvim-cmp source names with nixvim plugin module names. Internal option used to associate nvim-cmp source names with nixvim plugin module names.
@ -47,8 +45,8 @@ in
visible = false; visible = false;
}; };
plugins.cmp.autoEnableSources = mkOption { plugins.cmp.autoEnableSources = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = true; default = true;
example = false; example = false;
description = '' description = ''
@ -57,11 +55,12 @@ in
}; };
}; };
config = mkIf (cfg.enable && cfg.autoEnableSources) (mkMerge [ config = lib.mkIf (cfg.enable && cfg.autoEnableSources) (
lib.mkMerge [
{ {
warnings = warnings =
# TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions # TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions
optional (lib.types.isRawType cfg.settings.sources) '' lib.optional (lib.types.isRawType cfg.settings.sources) ''
Nixvim (plugins.cmp): You have enabled `autoEnableSources` that tells Nixvim to automatically 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`. 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. However, the latter is proveded as a raw lua string which is not parseable by Nixvim.
@ -71,7 +70,7 @@ in
- Dismiss this warning by explicitly setting `autoEnableSources` to `false`; - Dismiss this warning by explicitly setting `autoEnableSources` to `false`;
'' ''
# TODO: Added 2024-09-22; remove after 24.11 # TODO: Added 2024-09-22; remove after 24.11
++ optional (elem "otter" enabledSources) '' ++ lib.optional (lib.elem "otter" enabledSources) ''
Nixvim (plugins.cmp): "otter" is listed in `settings.sources`, however it is no longer a cmp source. Nixvim (plugins.cmp): "otter" is listed in `settings.sources`, however it is no longer a cmp source.
Instead, you should enable `plugins.otter` and use the "cmp-nvim-lsp" completion source. Instead, you should enable `plugins.otter` and use the "cmp-nvim-lsp" completion source.
''; '';
@ -81,15 +80,16 @@ in
# cmp-foo.enable = true; # cmp-foo.enable = true;
# cmp-bar.enable = true; # cmp-bar.enable = true;
# } # }
plugins = mapAttrs' (source: name: { plugins = lib.mapAttrs' (source: name: {
inherit name; inherit name;
value.enable = mkIf (elem source enabledSources) true; value.enable = lib.mkIf (lib.elem source enabledSources) true;
}) config.cmpSourcePlugins; }) config.cmpSourcePlugins;
} }
{ {
plugins.lsp.capabilities = mkIf (elem "nvim_lsp" enabledSources) '' plugins.lsp.capabilities = lib.mkIf (lib.elem "nvim_lsp" enabledSources) ''
capabilities = vim.tbl_deep_extend("force", capabilities, require('cmp_nvim_lsp').default_capabilities()) capabilities = vim.tbl_deep_extend("force", capabilities, require('cmp_nvim_lsp').default_capabilities())
''; '';
} }
]); ]
);
} }

View file

@ -6,13 +6,12 @@
let let
cmpOptions = import ./options { inherit lib helpers; }; cmpOptions = import ./options { inherit lib helpers; };
in in
with lib;
helpers.neovim-plugin.mkNeovimPlugin { helpers.neovim-plugin.mkNeovimPlugin {
name = "cmp"; name = "cmp";
originalName = "nvim-cmp"; originalName = "nvim-cmp";
package = "nvim-cmp"; package = "nvim-cmp";
maintainers = [ maintainers.GaetanLepage ]; maintainers = [ lib.maintainers.GaetanLepage ];
description = '' description = ''
### Completion Source Installation ### Completion Source Installation
@ -76,13 +75,13 @@ helpers.neovim-plugin.mkNeovimPlugin {
cmp.setup(${helpers.toLuaObject cfg.settings}) cmp.setup(${helpers.toLuaObject cfg.settings})
'' ''
+ (concatStringsSep "\n" ( + (lib.concatStringsSep "\n" (
mapAttrsToList ( lib.mapAttrsToList (
filetype: settings: "cmp.setup.filetype('${filetype}', ${helpers.toLuaObject settings})\n" filetype: settings: "cmp.setup.filetype('${filetype}', ${helpers.toLuaObject settings})\n"
) cfg.filetype ) cfg.filetype
)) ))
+ (concatStringsSep "\n" ( + (lib.concatStringsSep "\n" (
mapAttrsToList ( lib.mapAttrsToList (
cmdtype: settings: "cmp.setup.cmdline('${cmdtype}', ${helpers.toLuaObject settings})\n" cmdtype: settings: "cmp.setup.cmdline('${cmdtype}', ${helpers.toLuaObject settings})\n"
) cfg.cmdline ) cfg.cmdline
)); ));

View file

@ -1,6 +1,7 @@
{ lib, ... }: { lib, ... }:
with lib;
let let
inherit (lib) mkRenamedOptionModule mkRemovedOptionModule;
oldPluginBasePath = [ oldPluginBasePath = [
"plugins" "plugins"
"nvim-cmp" "nvim-cmp"

View file

@ -1,5 +1,4 @@
{ lib, helpers }: { lib, helpers }:
with lib;
rec { rec {
settingsOptions = import ./settings-options.nix { inherit lib helpers; }; settingsOptions = import ./settings-options.nix { inherit lib helpers; };
@ -28,13 +27,13 @@ rec {
}; };
attrsOfOptions = attrsOfOptions =
with types; with lib.types;
attrsOf (submodule { attrsOf (submodule {
freeformType = attrsOf anything; freeformType = attrsOf anything;
options = settingsOptions; options = settingsOptions;
}); });
filetype = mkOption { filetype = lib.mkOption {
type = attrsOfOptions; type = attrsOfOptions;
default = { }; default = { };
description = "Options provided to the `require('cmp').setup.filetype` function."; description = "Options provided to the `require('cmp').setup.filetype` function.";
@ -45,7 +44,7 @@ rec {
}; };
}; };
cmdline = mkOption { cmdline = lib.mkOption {
type = attrsOfOptions; type = attrsOfOptions;
default = { }; default = { };
description = "Options provided to the `require('cmp').setup.cmdline` function."; description = "Options provided to the `require('cmp').setup.cmdline` function.";

View file

@ -1,5 +1,7 @@
{ lib, helpers }: { lib, helpers }:
with lib; let
inherit (lib) mkOption types;
in
{ {
performance = { performance = {
debounce = helpers.defaultNullOpts.mkUnsignedInt 60 '' debounce = helpers.defaultNullOpts.mkUnsignedInt 60 ''
@ -261,7 +263,9 @@ with lib;
in in
{ {
completion = { completion = {
border = helpers.defaultNullOpts.mkBorder (genList (_: "") 8) "nvim-cmp completion popup menu" ""; border = helpers.defaultNullOpts.mkBorder (lib.genList (
_: ""
) 8) "nvim-cmp completion popup menu" "";
winhighlight = mkWinhighlightOption "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None"; winhighlight = mkWinhighlightOption "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None";
@ -286,7 +290,7 @@ with lib;
}; };
documentation = { documentation = {
border = helpers.defaultNullOpts.mkBorder (genList ( border = helpers.defaultNullOpts.mkBorder (lib.genList (
_: "" _: ""
) 8) "nvim-cmp documentation popup menu" ""; ) 8) "nvim-cmp documentation popup menu" "";

View file

@ -1,10 +1,11 @@
{ lib, helpers }: { lib, helpers }:
with lib;
let let
inherit (lib) types;
sourceType = types.submodule { sourceType = types.submodule {
freeformType = with types; attrsOf anything; freeformType = with types; attrsOf anything;
options = { options = {
name = mkOption { name = lib.mkOption {
type = types.str; type = types.str;
description = "The name of the source."; description = "The name of the source.";
example = "buffer"; example = "buffer";
@ -79,7 +80,7 @@ let
}; };
}; };
in in
mkOption { lib.mkOption {
default = [ ]; default = [ ];
type = with lib.types; maybeRaw (listOf sourceType); type = with lib.types; maybeRaw (listOf sourceType);
description = '' description = ''

View file

@ -4,12 +4,11 @@
config, config,
... ...
}: }:
with lib;
let let
cfg = config.plugins.cmp-ai; cfg = config.plugins.cmp-ai;
in in
{ {
meta.maintainers = [ maintainers.GaetanLepage ]; meta.maintainers = [ lib.maintainers.GaetanLepage ];
options.plugins.cmp-ai = { options.plugins.cmp-ai = {
settings = helpers.mkSettingsOption { settings = helpers.mkSettingsOption {
@ -31,7 +30,7 @@ in
available options. available options.
''; '';
provider_options = helpers.defaultNullOpts.mkAttrsOf types.anything { } '' provider_options = helpers.defaultNullOpts.mkAttrsOf lib.types.anything { } ''
Options to forward to the provider. Options to forward to the provider.
''; '';
@ -60,7 +59,7 @@ in
}; };
ignored_file_types = helpers.defaultNullOpts.mkAttrsOf' { ignored_file_types = helpers.defaultNullOpts.mkAttrsOf' {
type = types.bool; type = lib.types.bool;
description = "Which filetypes to ignore."; description = "Which filetypes to ignore.";
pluginDefault = { }; pluginDefault = { };
example = { example = {
@ -87,7 +86,7 @@ in
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
extraConfigLua = '' extraConfigLua = ''
require('cmp_ai.config'):setup(${helpers.toLuaObject cfg.settings}) require('cmp_ai.config'):setup(${helpers.toLuaObject cfg.settings})
''; '';

View file

@ -2,15 +2,13 @@
lib, lib,
config, config,
pkgs, pkgs,
helpers,
... ...
}: }:
with lib;
let let
cfg = config.plugins.cmp-fish; cfg = config.plugins.cmp-fish;
in in
{ {
meta.maintainers = [ maintainers.GaetanLepage ]; meta.maintainers = [ lib.maintainers.GaetanLepage ];
options.plugins.cmp-fish = { options.plugins.cmp-fish = {
fishPackage = lib.mkPackageOption pkgs "fish" { fishPackage = lib.mkPackageOption pkgs "fish" {
@ -18,5 +16,5 @@ in
}; };
}; };
config = mkIf cfg.enable { extraPackages = [ cfg.fishPackage ]; }; config = lib.mkIf cfg.enable { extraPackages = [ cfg.fishPackage ]; };
} }

View file

@ -4,14 +4,14 @@
config, config,
... ...
}: }:
with lib;
let let
inherit (lib) types;
cfg = config.plugins.cmp-git; cfg = config.plugins.cmp-git;
mkAction = mkAction =
action: target: action: target:
helpers.defaultNullOpts.mkLuaFn "require('cmp_git.${action}').git.${target}" '' helpers.defaultNullOpts.mkLuaFn "require('cmp_git.${action}').git.${target}" ''
Function used to ${action} the ${replaceStrings [ "_" ] [ " " ] target}. Function used to ${action} the ${lib.replaceStrings [ "_" ] [ " " ] target}.
''; '';
in in
{ {
@ -151,7 +151,7 @@ in
options = { options = {
debug_name = helpers.mkNullOrStr "Debug name."; debug_name = helpers.mkNullOrStr "Debug name.";
trigger_character = mkOption { trigger_character = lib.mkOption {
type = types.str; type = types.str;
example = ":"; example = ":";
description = '' description = ''
@ -160,7 +160,7 @@ in
''; '';
}; };
action = mkOption { action = lib.mkOption {
type = lib.types.strLuaFn; type = lib.types.strLuaFn;
description = '' description = ''
The parameters to the action function are the different sources (currently `git`, The parameters to the action function are the different sources (currently `git`,
@ -289,7 +289,7 @@ in
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
extraConfigLua = '' extraConfigLua = ''
require('cmp_git').setup(${helpers.toLuaObject cfg.settings}) require('cmp_git').setup(${helpers.toLuaObject cfg.settings})
''; '';

View file

@ -4,12 +4,12 @@
config, config,
... ...
}: }:
with lib;
let let
inherit (lib) mkRenamedOptionModule types;
cfg = config.plugins.cmp-tabby; cfg = config.plugins.cmp-tabby;
in in
{ {
meta.maintainers = [ maintainers.GaetanLepage ]; meta.maintainers = [ lib.maintainers.GaetanLepage ];
# TODO: introduced 24-06-18, remove after 24.11 # TODO: introduced 24-06-18, remove after 24.11
imports = imports =
@ -61,7 +61,7 @@ in
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
extraConfigLua = '' extraConfigLua = ''
require('cmp_tabby.config'):setup(${helpers.toLuaObject cfg.settings}) require('cmp_tabby.config'):setup(${helpers.toLuaObject cfg.settings})
''; '';

View file

@ -4,14 +4,13 @@
config, config,
... ...
}: }:
with lib;
let let
cfg = config.plugins.cmp-tabnine; cfg = config.plugins.cmp-tabnine;
in in
{ {
options.plugins.cmp-tabnine = helpers.neovim-plugin.extraOptionsOptions; options.plugins.cmp-tabnine = helpers.neovim-plugin.extraOptionsOptions;
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
extraConfigLua = '' extraConfigLua = ''
require('cmp_tabnine.config'):setup(${helpers.toLuaObject cfg.extraOptions}) require('cmp_tabnine.config'):setup(${helpers.toLuaObject cfg.extraOptions})
''; '';

View file

@ -4,7 +4,6 @@
config, config,
... ...
}: }:
with lib;
let let
copilot-lua-cfg = config.plugins.copilot-lua; copilot-lua-cfg = config.plugins.copilot-lua;
cfg = config.plugins.copilot-cmp; cfg = config.plugins.copilot-cmp;
@ -12,7 +11,7 @@ in
{ {
options.plugins.copilot-cmp = helpers.neovim-plugin.extraOptionsOptions // { options.plugins.copilot-cmp = helpers.neovim-plugin.extraOptionsOptions // {
event = event =
helpers.defaultNullOpts.mkListOf types.str helpers.defaultNullOpts.mkListOf lib.types.str
[ [
"InsertEnter" "InsertEnter"
"LspAttach" "LspAttach"
@ -35,13 +34,15 @@ in
''; '';
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
warnings = warnings =
optional ((!isBool copilot-lua-cfg.suggestion.enabled) || copilot-lua-cfg.suggestion.enabled) '' lib.optional
((!lib.isBool copilot-lua-cfg.suggestion.enabled) || copilot-lua-cfg.suggestion.enabled)
''
It is recommended to disable copilot's `suggestion` module, as it can interfere with It is recommended to disable copilot's `suggestion` module, as it can interfere with
completions properly appearing in copilot-cmp. completions properly appearing in copilot-cmp.
'' ''
++ optional ((!isBool copilot-lua-cfg.panel.enabled) || copilot-lua-cfg.panel.enabled) '' ++ lib.optional ((!lib.isBool copilot-lua-cfg.panel.enabled) || copilot-lua-cfg.panel.enabled) ''
It is recommended to disable copilot's `panel` module, as it can interfere with completions It is recommended to disable copilot's `panel` module, as it can interfere with completions
properly appearing in copilot-cmp. properly appearing in copilot-cmp.
''; '';

View file

@ -4,14 +4,13 @@
config, config,
... ...
}: }:
with lib;
let let
cfg = config.plugins.crates-nvim; cfg = config.plugins.crates-nvim;
in in
{ {
options.plugins.crates-nvim = helpers.neovim-plugin.extraOptionsOptions; options.plugins.crates-nvim = helpers.neovim-plugin.extraOptionsOptions;
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
extraConfigLua = '' extraConfigLua = ''
require('crates').setup(${helpers.toLuaObject cfg.extraOptions}) require('crates').setup(${helpers.toLuaObject cfg.extraOptions})
''; '';