From 62b87e5b5672650727aff6a6bda61cee598715ac Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 6 Oct 2024 09:57:31 -0500 Subject: [PATCH] plugins/cmp: remove with lib; --- plugins/cmp/auto-enable.nix | 92 ++++++++++++------------ plugins/cmp/default.nix | 11 ++- plugins/cmp/deprecations.nix | 3 +- plugins/cmp/options/default.nix | 7 +- plugins/cmp/options/settings-options.nix | 10 ++- plugins/cmp/options/sources-option.nix | 7 +- plugins/cmp/sources/cmp-ai.nix | 9 ++- plugins/cmp/sources/cmp-fish.nix | 6 +- plugins/cmp/sources/cmp-git.nix | 10 +-- plugins/cmp/sources/cmp-tabby.nix | 6 +- plugins/cmp/sources/cmp-tabnine.nix | 3 +- plugins/cmp/sources/copilot-cmp.nix | 17 ++--- plugins/cmp/sources/crates-nvim.nix | 3 +- 13 files changed, 92 insertions(+), 92 deletions(-) diff --git a/plugins/cmp/auto-enable.nix b/plugins/cmp/auto-enable.nix index 44859cf4..eda5473f 100644 --- a/plugins/cmp/auto-enable.nix +++ b/plugins/cmp/auto-enable.nix @@ -1,38 +1,36 @@ { lib, - helpers, config, ... }: -with lib; let 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 # ["foo" "bar"] enabledSources = - pipe + lib.pipe [ # cfg.setup.sources (extractSources cfg.settings) # cfg.filetype..sources - (mapAttrsToList (_: extractSources) cfg.filetype) + (lib.mapAttrsToList (_: extractSources) cfg.filetype) # cfg.cmdline..sources - (mapAttrsToList (_: extractSources) cfg.cmdline) + (lib.mapAttrsToList (_: extractSources) cfg.cmdline) ] [ - flatten - (map (getAttr "name")) - unique + lib.flatten + (map (lib.getAttr "name")) + lib.unique ]; in { options = { # Note: this option must be outside of `plugins` to avoid infinite recursion - cmpSourcePlugins = mkOption { - type = with types; attrsOf str; + cmpSourcePlugins = lib.mkOption { + type = with lib.types; attrsOf str; default = { }; description = '' Internal option used to associate nvim-cmp source names with nixvim plugin module names. @@ -47,8 +45,8 @@ in visible = false; }; - plugins.cmp.autoEnableSources = mkOption { - type = types.bool; + plugins.cmp.autoEnableSources = lib.mkOption { + type = lib.types.bool; default = true; example = false; description = '' @@ -57,39 +55,41 @@ in }; }; - config = mkIf (cfg.enable && cfg.autoEnableSources) (mkMerge [ - { - warnings = - # TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions - optional (lib.types.isRawType cfg.settings.sources) '' - 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`. - However, the latter is proveded as a raw lua string which is not parseable by Nixvim. + config = lib.mkIf (cfg.enable && cfg.autoEnableSources) ( + lib.mkMerge [ + { + warnings = + # TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions + lib.optional (lib.types.isRawType cfg.settings.sources) '' + 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`. + However, the latter is proveded as a raw lua string which is not parseable by Nixvim. - If you want to keep using raw lua for defining your sources: - - Ensure you enable the relevant plugins manually in your configuration; - - Dismiss this warning by explicitly setting `autoEnableSources` to `false`; - '' - # TODO: Added 2024-09-22; remove after 24.11 - ++ optional (elem "otter" enabledSources) '' - 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. + If you want to keep using raw lua for defining your sources: + - Ensure you enable the relevant plugins manually in your configuration; + - Dismiss this warning by explicitly setting `autoEnableSources` to `false`; + '' + # TODO: Added 2024-09-22; remove after 24.11 + ++ lib.optional (lib.elem "otter" enabledSources) '' + 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. + ''; + + # If the user has enabled the `foo` and `bar` sources, then `plugins` will look like: + # { + # cmp-foo.enable = true; + # cmp-bar.enable = true; + # } + plugins = lib.mapAttrs' (source: name: { + inherit name; + value.enable = lib.mkIf (lib.elem source enabledSources) true; + }) config.cmpSourcePlugins; + } + { + plugins.lsp.capabilities = lib.mkIf (lib.elem "nvim_lsp" enabledSources) '' + capabilities = vim.tbl_deep_extend("force", capabilities, require('cmp_nvim_lsp').default_capabilities()) ''; - - # If the user has enabled the `foo` and `bar` sources, then `plugins` will look like: - # { - # cmp-foo.enable = true; - # cmp-bar.enable = true; - # } - plugins = mapAttrs' (source: name: { - inherit name; - value.enable = mkIf (elem source enabledSources) true; - }) config.cmpSourcePlugins; - } - { - plugins.lsp.capabilities = mkIf (elem "nvim_lsp" enabledSources) '' - capabilities = vim.tbl_deep_extend("force", capabilities, require('cmp_nvim_lsp').default_capabilities()) - ''; - } - ]); + } + ] + ); } diff --git a/plugins/cmp/default.nix b/plugins/cmp/default.nix index 06db25ea..d3b44e8b 100644 --- a/plugins/cmp/default.nix +++ b/plugins/cmp/default.nix @@ -6,13 +6,12 @@ let cmpOptions = import ./options { inherit lib helpers; }; in -with lib; helpers.neovim-plugin.mkNeovimPlugin { name = "cmp"; originalName = "nvim-cmp"; package = "nvim-cmp"; - maintainers = [ maintainers.GaetanLepage ]; + maintainers = [ lib.maintainers.GaetanLepage ]; description = '' ### Completion Source Installation @@ -76,13 +75,13 @@ helpers.neovim-plugin.mkNeovimPlugin { cmp.setup(${helpers.toLuaObject cfg.settings}) '' - + (concatStringsSep "\n" ( - mapAttrsToList ( + + (lib.concatStringsSep "\n" ( + lib.mapAttrsToList ( filetype: settings: "cmp.setup.filetype('${filetype}', ${helpers.toLuaObject settings})\n" ) cfg.filetype )) - + (concatStringsSep "\n" ( - mapAttrsToList ( + + (lib.concatStringsSep "\n" ( + lib.mapAttrsToList ( cmdtype: settings: "cmp.setup.cmdline('${cmdtype}', ${helpers.toLuaObject settings})\n" ) cfg.cmdline )); diff --git a/plugins/cmp/deprecations.nix b/plugins/cmp/deprecations.nix index ec972508..2003cbdc 100644 --- a/plugins/cmp/deprecations.nix +++ b/plugins/cmp/deprecations.nix @@ -1,6 +1,7 @@ { lib, ... }: -with lib; let + inherit (lib) mkRenamedOptionModule mkRemovedOptionModule; + oldPluginBasePath = [ "plugins" "nvim-cmp" diff --git a/plugins/cmp/options/default.nix b/plugins/cmp/options/default.nix index 6f9143cd..6e62eac3 100644 --- a/plugins/cmp/options/default.nix +++ b/plugins/cmp/options/default.nix @@ -1,5 +1,4 @@ { lib, helpers }: -with lib; rec { settingsOptions = import ./settings-options.nix { inherit lib helpers; }; @@ -28,13 +27,13 @@ rec { }; attrsOfOptions = - with types; + with lib.types; attrsOf (submodule { freeformType = attrsOf anything; options = settingsOptions; }); - filetype = mkOption { + filetype = lib.mkOption { type = attrsOfOptions; default = { }; description = "Options provided to the `require('cmp').setup.filetype` function."; @@ -45,7 +44,7 @@ rec { }; }; - cmdline = mkOption { + cmdline = lib.mkOption { type = attrsOfOptions; default = { }; description = "Options provided to the `require('cmp').setup.cmdline` function."; diff --git a/plugins/cmp/options/settings-options.nix b/plugins/cmp/options/settings-options.nix index e4c8cd26..e2ba75d4 100644 --- a/plugins/cmp/options/settings-options.nix +++ b/plugins/cmp/options/settings-options.nix @@ -1,5 +1,7 @@ { lib, helpers }: -with lib; +let + inherit (lib) mkOption types; +in { performance = { debounce = helpers.defaultNullOpts.mkUnsignedInt 60 '' @@ -261,7 +263,9 @@ with lib; in { 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"; @@ -286,7 +290,7 @@ with lib; }; documentation = { - border = helpers.defaultNullOpts.mkBorder (genList ( + border = helpers.defaultNullOpts.mkBorder (lib.genList ( _: "" ) 8) "nvim-cmp documentation popup menu" ""; diff --git a/plugins/cmp/options/sources-option.nix b/plugins/cmp/options/sources-option.nix index d6429fa9..c2b19995 100644 --- a/plugins/cmp/options/sources-option.nix +++ b/plugins/cmp/options/sources-option.nix @@ -1,10 +1,11 @@ { lib, helpers }: -with lib; let + inherit (lib) types; + sourceType = types.submodule { freeformType = with types; attrsOf anything; options = { - name = mkOption { + name = lib.mkOption { type = types.str; description = "The name of the source."; example = "buffer"; @@ -79,7 +80,7 @@ let }; }; in -mkOption { +lib.mkOption { default = [ ]; type = with lib.types; maybeRaw (listOf sourceType); description = '' diff --git a/plugins/cmp/sources/cmp-ai.nix b/plugins/cmp/sources/cmp-ai.nix index 3754a2f9..070fe301 100644 --- a/plugins/cmp/sources/cmp-ai.nix +++ b/plugins/cmp/sources/cmp-ai.nix @@ -4,12 +4,11 @@ config, ... }: -with lib; let cfg = config.plugins.cmp-ai; in { - meta.maintainers = [ maintainers.GaetanLepage ]; + meta.maintainers = [ lib.maintainers.GaetanLepage ]; options.plugins.cmp-ai = { settings = helpers.mkSettingsOption { @@ -31,7 +30,7 @@ in available options. ''; - provider_options = helpers.defaultNullOpts.mkAttrsOf types.anything { } '' + provider_options = helpers.defaultNullOpts.mkAttrsOf lib.types.anything { } '' Options to forward to the provider. ''; @@ -60,7 +59,7 @@ in }; ignored_file_types = helpers.defaultNullOpts.mkAttrsOf' { - type = types.bool; + type = lib.types.bool; description = "Which filetypes to ignore."; pluginDefault = { }; example = { @@ -87,7 +86,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { extraConfigLua = '' require('cmp_ai.config'):setup(${helpers.toLuaObject cfg.settings}) ''; diff --git a/plugins/cmp/sources/cmp-fish.nix b/plugins/cmp/sources/cmp-fish.nix index ec65084c..772cfbf7 100644 --- a/plugins/cmp/sources/cmp-fish.nix +++ b/plugins/cmp/sources/cmp-fish.nix @@ -2,15 +2,13 @@ lib, config, pkgs, - helpers, ... }: -with lib; let cfg = config.plugins.cmp-fish; in { - meta.maintainers = [ maintainers.GaetanLepage ]; + meta.maintainers = [ lib.maintainers.GaetanLepage ]; options.plugins.cmp-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 ]; }; } diff --git a/plugins/cmp/sources/cmp-git.nix b/plugins/cmp/sources/cmp-git.nix index 9863835a..82bbf09e 100644 --- a/plugins/cmp/sources/cmp-git.nix +++ b/plugins/cmp/sources/cmp-git.nix @@ -4,14 +4,14 @@ config, ... }: -with lib; let + inherit (lib) types; cfg = config.plugins.cmp-git; mkAction = action: 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 { @@ -151,7 +151,7 @@ in options = { debug_name = helpers.mkNullOrStr "Debug name."; - trigger_character = mkOption { + trigger_character = lib.mkOption { type = types.str; example = ":"; description = '' @@ -160,7 +160,7 @@ in ''; }; - action = mkOption { + action = lib.mkOption { type = lib.types.strLuaFn; description = '' 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 = '' require('cmp_git').setup(${helpers.toLuaObject cfg.settings}) ''; diff --git a/plugins/cmp/sources/cmp-tabby.nix b/plugins/cmp/sources/cmp-tabby.nix index d967abe4..87e28467 100644 --- a/plugins/cmp/sources/cmp-tabby.nix +++ b/plugins/cmp/sources/cmp-tabby.nix @@ -4,12 +4,12 @@ config, ... }: -with lib; let + inherit (lib) mkRenamedOptionModule types; cfg = config.plugins.cmp-tabby; in { - meta.maintainers = [ maintainers.GaetanLepage ]; + meta.maintainers = [ lib.maintainers.GaetanLepage ]; # TODO: introduced 24-06-18, remove after 24.11 imports = @@ -61,7 +61,7 @@ in }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { extraConfigLua = '' require('cmp_tabby.config'):setup(${helpers.toLuaObject cfg.settings}) ''; diff --git a/plugins/cmp/sources/cmp-tabnine.nix b/plugins/cmp/sources/cmp-tabnine.nix index 11e679bd..2cdca7c8 100644 --- a/plugins/cmp/sources/cmp-tabnine.nix +++ b/plugins/cmp/sources/cmp-tabnine.nix @@ -4,14 +4,13 @@ config, ... }: -with lib; let cfg = config.plugins.cmp-tabnine; in { options.plugins.cmp-tabnine = helpers.neovim-plugin.extraOptionsOptions; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { extraConfigLua = '' require('cmp_tabnine.config'):setup(${helpers.toLuaObject cfg.extraOptions}) ''; diff --git a/plugins/cmp/sources/copilot-cmp.nix b/plugins/cmp/sources/copilot-cmp.nix index 157e7fd3..6cb3d44e 100644 --- a/plugins/cmp/sources/copilot-cmp.nix +++ b/plugins/cmp/sources/copilot-cmp.nix @@ -4,7 +4,6 @@ config, ... }: -with lib; let copilot-lua-cfg = config.plugins.copilot-lua; cfg = config.plugins.copilot-cmp; @@ -12,7 +11,7 @@ in { options.plugins.copilot-cmp = helpers.neovim-plugin.extraOptionsOptions // { event = - helpers.defaultNullOpts.mkListOf types.str + helpers.defaultNullOpts.mkListOf lib.types.str [ "InsertEnter" "LspAttach" @@ -35,13 +34,15 @@ in ''; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { warnings = - optional ((!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 - 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.suggestion.enabled) || copilot-lua-cfg.suggestion.enabled) + '' + It is recommended to disable copilot's `suggestion` module, as it can interfere with + completions properly appearing in copilot-cmp. + '' + ++ 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 properly appearing in copilot-cmp. ''; diff --git a/plugins/cmp/sources/crates-nvim.nix b/plugins/cmp/sources/crates-nvim.nix index a97fbccf..42cbb9ec 100644 --- a/plugins/cmp/sources/crates-nvim.nix +++ b/plugins/cmp/sources/crates-nvim.nix @@ -4,14 +4,13 @@ config, ... }: -with lib; let cfg = config.plugins.crates-nvim; in { options.plugins.crates-nvim = helpers.neovim-plugin.extraOptionsOptions; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { extraConfigLua = '' require('crates').setup(${helpers.toLuaObject cfg.extraOptions}) '';